www.webdeveloper.com
Results 1 to 2 of 2

Thread: Submitting forms thru javascript

  1. #1
    Join Date
    Jun 2005
    Posts
    81

    Submitting forms thru javascript

    I currently have the following page in which I call a function to check which button is clicked then submitting the form. However, I'm not able to get the form to submit. Can someone please help me?

    HTML Code:
    <html>
    <head>
        <title>ECD Form</title>
        <script type="text/javascript">
            function deleteECP(delYesNo) {
                if (delYesNo) {
                    delYN = confirm("Deleting this ECP will also delete all associated CNs.\n\nAre you sure you want to delete this ECP?");
                    if (delYN) {
                        document.form1.submit();
                    } else {
                        return false;
                    }
                } else {
                    document.form1.submit();
                }
            }
        </script>
    </head>
     
    <body>
     
        <form id="form1" action="ECD_propsSubform.asp" method="post">
            <input type="hidden" id="id" name="id" value="36" />
            <input type="hidden" name="ecpID" id="ecpID" value="2175" />
            <table cellspacing="1" border="0">
                <tr>
                    <td colspan="3">
                        <table width="100%" border="0">
                            <tr>
                                <td><img src="trnsp.gif" width="75" height="1" border="0" /></td>
                                <td><img src="trnsp.gif" width="270" height="1" border="0" /></td>
                                <td><img src="trnsp.gif" width="150" height="1" border="0" /></td>
                                <td><img src="trnsp.gif" width="150" height="1" border="0" /></td>
                            </tr>
                            <tr>
                                <td>ECP</td>
                                <td>Title</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr valign="top">
                                <td><input type="text" class="text" id="ecp" name="ecp" size="5" value="445" /></td>
                                <td><textarea name="title" id="title" rows="2" cols="50">Testing</textarea></td>
                            </tr>
                            <tr>
                                <td>Description</td>
                            </tr>
                            <tr>
                                <td colspan="3"><textarea name="desc" id="desc" rows="4" cols="80"></textarea></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="3" align="center"><input type="button" value="Update ECP Data" name="update" onclick="deleteECP(false)" id="update" />&nbsp;&nbsp;<input
                        type="button" onclick="deleteECP(true)" value="Delete ECP" name="delete" id="delete" /></td>
                </tr>
                
            </table>
        </form>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    the reference
    Code:
    document.form1
    is looking for an element with the name="form1", not with the id="form1". name and id are not the same (well, yes, IE do a mismatch in this case, but let's forget about it). Try this fully crossbrowser:
    Code:
    document.getElementById('form1').submit();
    Last edited by Kor; 07-28-2009 at 09:58 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles