Home >Web Front-end >JS Tutorial >JS method to control form submission_javascript skills

JS method to control form submission_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:50:531000browse

The example in this article describes the method of JS controlling form submission. Share it with everyone for your reference. The details are as follows:

<Script Language="JavaScript">
function autoSubmit(){
var form = document.forms[0];
var actionPath = "&#63;mo=phone";
form.action = actionPath;
form.submit();
return true;
}
</Script>

If you need two submit buttons, the attribute value of type="" is "submit" and the other is "button", that is, one is submitted by the button itself, and the other is submitted by JS control

<form method="post" name="form1" id="form1" action="&#63;mo=phone&do=opreat" >
<input type="hidden" value="" name="phoneid" id="phoneid">
 <table border="0px" style="font-size:12px" width="630px" >
  <tr>
   <td align="right">手机型号:</td>
   <td><input type="text" id="phonetype" name="phonetype" style="width:120px" <&#63;# if $pinfo.pass_var.phonetype &#63;>value="<&#63;# $pinfo.pass_var.phonetype &#63;>" <&#63;# /if &#63;> /></td>
   <td><div id="phonetypeTip" style="width:250px"></div></td>
  </tr>
  <tr>
   <td align="right">类型:</td>
   <td><select name="type" id="type">
     <&#63;# foreach from=$types item=value &#63;>
  <option value="<&#63;# $value.type &#63;>"
  <&#63;# if $pinfo.pass_var.type== $value.type &#63;>selected="selected"<&#63;# /if &#63;>><&#63;# $value.type &#63;>
  </option>
  <&#63;# /foreach &#63;>
     </select></td>
   <td><div id="typeTip" style="width:250px"></div></td>
  </tr>
  <tr>
   <td align="right">厂商:</td>
   <td><select name="brandid" id="brandid">
     <&#63;# foreach from=$brand item=value &#63;><option value="<&#63;# $value.brandid &#63;>" <&#63;# if $pinfo.pass_var.brandid== $value.brandid &#63;>selected="selected"<&#63;# /if &#63;> ><&#63;# $value.name_zh &#63;></option><&#63;# /foreach &#63;>
     </select></td>
   <td><div id="brandidTip" style="width:250px"></div></td>
  </tr>
</table>
<input type="submit" value="增加手机" >
<input type="button" onclick="autoSubmit();" value="搜索手机" >
</form>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn