Page 1 of 1

How to submit from javascript

Posted: Wed Dec 17, 2008 2:52 pm
by erbrmn

There are 2 buttons, I want to submit forum from javascript code.
It is not work, how can I submit when I have several buttons in single forum, please advice me.

Code: Select all

 
<html>
<head>
  <script language="JavaScript">
  <!--
    function funcSubmitform(p_url) {
 
      if (confirm("Really ?"))
      {
        frmMain.action = p_url;
        frmMain.submit();
        return true;
      } else {
        return false;
      }
    }
  //-->
</script>
</head>
<body>
<form method="POST" name="frmMain">
<div align="center">
  <table border="0" width="100%" border="0" cellpadding="6" cellspacing="1">
    <tr>
      <td class="title">ID :</td>
        <td class="item"><input name="txtUserID" value="" tabindex = "1" type="text" size="40" /></td>
    </tr>
    <tr>
      <td height="50" colspan="2" align="center" class="item">
        <input type="button" name="btnREG" value="UPDATE" onclick="funcSubmitform('file1.php');">
        <input type="button" name="btnDEL" value="DELETE" onclick="funcSubmitform('file1.php');">
      </td>
    </tr>
  </table>
</div>
</form>
</body></html>
 

Re: How to submit from javascript

Posted: Wed Dec 17, 2008 4:38 pm
by John Cartwright
Try changing

Code: Select all

frmMain.submit();
to

Code: Select all

document.frmMain.submit();
Better yet, google has ALOT to say on the matter

Re: How to submit from javascript

Posted: Wed Dec 17, 2008 4:59 pm
by erbrmn
Yes , I tried like this ,

Code: Select all

document.frmMain.submit();
also I searched from google.com, ..... but I still can not submit.

Re: How to submit from javascript

Posted: Wed Dec 17, 2008 6:19 pm
by John Cartwright
Does this example work?

Code: Select all

<script language="javaScript">
function SubmitForm()
{
    document.form1.submit();
}
</script>
 
<form name="form1" action="anotherpage.html">
<a href="#" onclick="SubmitForm()">Test Link</a>
</form>

Re: How to submit from javascript

Posted: Thu Dec 18, 2008 5:32 pm
by erbrmn
Jcart:

Thank you for advices, but I still can not submit it when I use normal link.
When I submit to normal html file It can link but not like real submit, I can not submit php file.

Have you any idea?