submit button isnt working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • soheir
    New Member
    • Oct 2007
    • 4

    submit button isnt working

    am doing my first project so plz help
    i've created a submit button
    [HTML]<input type="submit" onclick="valid( )">[/HTML]
    my function valid checks if the fields are not empty if empty a window prmpt appears then when i press ok i move to the next page
    for example
    [HTML]<script type="text/javascript">
    <!--
    function valid()
    {
    var n=document.form .fname.value.le ngth;
    if(n==0){
    window.alert("e nter ur first name");
    return false;
    } }
    //--></script>
    [/HTML]then the php code
    [HTML] <input type="submit" name="sub" value="Submit Your Entries" onclick="valid( )" />
    [/HTML]i wrote instead of type="submit" =>type="button " it works but when i fill all the fields am not moving to next page
    Last edited by acoder; Oct 5 '07, 07:07 AM. Reason: Added code tags
  • FullyH3ktik
    New Member
    • Sep 2007
    • 52

    #2
    what if you added this to your function:
    [CODE=Javascript]else
    {
    location.href=" URL goes here";
    }[/CODE]
    that way if the field is not blank, it will take you to the page specified.

    Comment

    • ajos
      Contributor
      • Aug 2007
      • 283

      #3
      Originally posted by soheir
      <input type="submit" onclick="valid( )">
      <script type="text/javascript">
      <!--
      function valid()
      {
      var n=document.form .fname.value.le ngth;
      if(n==0){
      window.alert("e nter ur first name");
      return false;
      } }
      //--></script>
      hi soheir,
      why are you using <!-- --> ? you are commenting the function that needs to be called...plz remove the comments...
      regards,
      ajos

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by soheir
        am doing my first project so plz help
        i've created a submit button
        <input type="submit" onclick="valid( )">
        my function valid checks if the fields are not empty if empty a window prmpt appears then when i press ok i move to the next page
        for example
        <script type="text/javascript">
        <!--
        function valid()
        {
        var n=document.form .fname.value.le ngth;
        if(n==0){
        window.alert("e nter ur first name");
        return false;
        } }
        //--></script>
        then the php code
        <input type="submit" name="sub" value="Submit Your Entries" onclick="valid( )" />
        i wrote instead of type="submit" =>type="button " it works but when i fill all the fields am not moving to next page

        Use code Tags buddy :-)
        Please read the posting guidelines before you post.

        Have a look at this ....

        [code=html]
        <form onsubmit = "return valid();">
        .
        .
        </form>
        [/code]

        [code=javascript]
        function valid()
        {
        return (condition_sati sfies);
        }
        [/code]

        Debasis Jana

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, ajos.

          Originally posted by ajos
          why are you using <!-- --> ? you are commenting the function that needs to be called...plz remove the comments...
          The code is not actually commented. It's an old trick to prevent *really* older browsers (does anyone use a browser that doesn't know what JavaScript is anymore?) from displaying JavaScript code on the web page. But all modern browsers know that the code isn't *really* commented.

          Nowadays, the bigger concern is XML compatibility. That's why you often see:
          [code=html]
          <script type="text/javascript">
          // <![CDATA[
          // ]]>
          </script>
          [/code]

          Comment

          • ajos
            Contributor
            • Aug 2007
            • 283

            #6
            Originally posted by pbmods
            Heya, ajos.
            The code is not actually commented. It's an old trick to prevent *really* older browsers (does anyone use a browser that doesn't know what JavaScript is anymore?) from displaying JavaScript code on the web page. But all modern browsers know that the code isn't *really* commented.

            Nowadays, the bigger concern is XML compatibility. That's why you often see:
            [code=html]
            <script type="text/javascript">
            // <![CDATA[
            // ]]>
            </script>
            [/code]
            hey pbmods,
            thanks for correcting me regarding this, i got stumped by seeing <!-- --> this in the first place(not common to see actually).:-)
            this forum is great...keep up the good work friends!!!
            regards,
            ajos

            Comment

            Working...