如何通过javascript提交表单form
来源:互联网 发布:搜索引擎源码 带爬虫 编辑:程序博客网 时间:2024/06/06 12:40
如何通过javascript提交表单form
(2011-09-13 14:53:51)转载▼
标签:
javascript
杂谈
分类: php常见--How to Submit a Form Using JavaScript
Generally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using JavaScript.
JavaScript provides the form object that contains the submit() method. Use the ‘id’ of the form to get the form object.
For example, if the name of your form is ‘myform’, the JavaScript code for the submit call is:
document.forms[
"myform"
].submit();
But, how to identify a form? Give an id attribute in the form tag
<
form
id
=
'myform'
action
=
'formmail.pl'
>
Here is the code to submit a form when a hyperlink is clicked:
<
form
name
=
"myform"
action
=
"handle-data.php"
>
Search: <
input
type
=
'text'
name
=
'query'
/>
<
a
href
=
"javascript: submitform()"
>Search</
a
>
</
form
>
<
script
type
=
"text/javascript"
>
function submitform()
{
document.myform.submit();
}
</
script
>
JavaScript Form Submit Example 1
<html><head>url</head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<body>
<form name="testForm" id="testForm" mothod="GET">
<input type="text" name="test1" id="order" value="order">
<input type="text" name="test2" value="get2">
<input type="submit" name="Submit" value="yes" >
<a href="javascript: submitform();">submit</a>
</form>
<script type="text/javascript">
function submitform()
{
// document.forms['testForm'].submit(); //this will be ok,here is name="testForm"
$('testForm').submit(); //here is id="testForm"
}
function $(xxx)
{
return document.getElementByIdx_x_x_x(xxx);
}
</script>
</body>
</html>
阅读(6159)┊ 评论 (0)┊收藏(0) ┊转载(0)┊ 喜欢▼ ┊打印┊举报
排行榜
前一篇:linux下导入、导出mysql数据库命令
后一篇:$(document).ready说明
0 0
- 如何通过javascript提交表单form
- 如何通过javascript提交表单form
- 如何通过jquery禁止form表单提交
- javascript提交form表单
- JavaScript提交form表单
- Javascript提交form表单
- 通过ajax提交form表单
- form表单提交如何验证?
- Jquery通过Ajax方式提交Form表单
- javaWeb通过iframe异步提交form表单
- document.form.action,表单分向提交,javascript提交表单
- document.form.action,表单分向提交,javascript提交表单
- document.form.action,表单分向提交,javascript提交表单
- JavaScript 或者 jQuery 拼接form表单提交
- js提交form表单(Javascript)
- 写在js文件里的变量如何通过FORM表单提交到action
- 如何通过submit提交form表单获取后台传来的返回值
- 如何解决Form表单的重复提交
- Unity3D的特殊目录名称
- 【宽搜】Vijos P1206 CoVH之再破难关
- 防火墙
- 虚继承
- windows server 2008解决盘符C盘变D盘的安装方法
- 如何通过javascript提交表单form
- MyEclipse快捷键大全
- Java的多线程机制系列:不得不提的volatile及指令重排序
- Red Hat 6.5 配置 CentOS 6.5 Yum 源
- 个人所得税计算
- 对三层架构的浅层理解
- 2016-03-21文件操作
- 2016-03-21集合泛型集合、队列和栈
- ntohs, ntohl, htons,htonl, inet_addr,inet_ntoa区别