Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    onsubmit Function not called first time in IE

    Hi, I'm pretty new to javascript so could someone please help me with this problem? I'm calling a custom function called validate() from a form's onsubmit handler through onsubmit="return validate()" . However,while this works in Firefox, the function is called the first time I submit instead it just submits immediately. However, following submits go to the function. Can someone please help? The function is just for testing as follows:

    function validate(){
    alert("yo");
    return false;
    }

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Can we have a link to see the real action?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have the file on localhost. Is there somewhere I can upload it to?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Then post your complete code(html+javascript) here.
    PS: please follow http://www.codingforums.com/showthread.php?t=82672 on how to post your code.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Jul 2008
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Its a little bigger than I'd like so im cutting a few non-important bits out. I'm putting it all in code tags.

    Code:
    <HTML>
    <head>
    <script type="text/javascript">
    var list1;
    var list2;
    var list1Clone;
    var cloneOptions;
    
    function createListObjects(){
        list1 = document.getElementById("list1");
        list2 = document.getElementById("list2");
        //alert(list2.options.item(0).value);
        //alert(document.forms[0].list1.options.item[0].value);
        //list1Clone=list1.cloneNode(true);
        //cloneOptions=list1Clone.getElementsByTagName("option");
        //but =  document.getElementById("test");
        //but.onclick = test;
    
    }
    function delAttribute(){
       var selIndex = list2.selectedIndex;
       if(selIndex < 0)
          return;
       list2.removeChild(list2.options.item(selIndex));
    }
    function addAttribute(){
       var addIndex = list1.selectedIndex;
       alert(addIndex);
       if(addIndex < 0)
          return;
       list2.appendChild(list1.options.item(addIndex));
    }
    function validate(){
    	  alert("yo");
    	  return false;
    }
    </script>
    </head>
    <body onload="createListObjects()">
    <?php
      if (isset($_POST['send'])){
        print_r($_POST);
      }
    ?>
    <form method="post" name="add" action="test.php" onsubmit="return validate()">
        <table border="1">
          <tr>
            <td><select size="4" 
              id="list1" 
              name="list1">
              <option value="option1">
                option1
              </option>
    
              <option value="option3">
                option3
              </option></select></td>
    
            <td >
             <button onclick="addAttribute()">
                ></button> 
            <br>
             <button onclick="delAttribute()">
                <</button> 
            </td>
    
            <td><select size="4" 
               id="list2" 
               name="list2">
              <option value="option2">
                option2
              </option>
    
              <option value="option4">
                option4
              </option>
            </select></td>
           </tr>
        </table>
        <input type="submit" name="send" value="Send">
        <input type="hidden" name="allopt">
    </form>
    </body>
    </html>

  • #6
    New Coder
    Join Date
    Jul 2008
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is all in a .php file by the way.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    It works for me as intended. No such problems.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    New Coder
    Join Date
    Jul 2008
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Strange, I just tried rebuilding the same file piece by piece and it stayed working. I dunno what was wrong the first time. Thanks anyway. You must be good luck or something.

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Probably you forgot to refresh the page after adding the script for the first time.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    satsujin (08-04-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •