![](/img/trans.png)
[英]i want to submit a form but before submit i want to take a value from modal form
[英]i want to get value from the form using javascript before submit
我想从输入文本表单中获取价值,并在提交之前将其发送给php。
例如:PHP文件:
$do="FORM VALUE HERE"; //HERE IS $_POST['search'];
$result = mysql_query("SELECT * FROM table WHERE name='$do'");
while($row = mysql_fetch_array($result))
{
$code=$row['code_number'];
}
HTML:
<script >
HERE WHAT I WANT TO DO
<script />
形成:
<form action="view_results.php?code=<? echo $code ?>" method="post">
<input type="text" name="search" /><br />
<input type="submit" value="search" />
<form />
因此,在此示例中,我想在单击以提交botton之前获取$ do = $ _ POST ['search'],以便可以从mySQL中选择结果以在下一页中进行查看。
谢谢
你能赶上表单的提交事件,取消它,抓住你想要的形式价值,使你的PHP后,当这样做了,回去提交表单。
<form id="form1" action="view_results.php?code=<? echo $code ?>" method="post">
document.forms["form1"].onsubmit = function(e) {
e.preventDefault(); //cancel form submit
var searchValue = this.search.value;
var self = this;
//post searchValue to your PHP page using your favorite JS library,
//then in the call back, submit your form with self.submit();
};
<form action="view_results.php?code=<? echo $code ?>" method="post" onsubmit="beforeSubmit(event)">
<input type="text" name="search" /><br />
<input type="submit" value="search" />
<form />
<script >
//HERE WHAT I WANT TO DO
function beforeSubmit(event){
event.preventDefault();
var form = event.currentTarget;
// form.search.value will give the text in search
}
<script />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.