I am using a form to submit the data to get the records from the database.
In the form I am using the two select tag options.
我正在使用表单提交数据以从数据库中获取记录。在表单中我使用了两个选择标记选项。
So after selecting the options the form should submit without using the submit button. I am waiting for the response to submit the form after selecting the inputs without using the submit button(or any button) it should submit automatically.
因此,在选择选项后,表单应该在不使用提交按钮的情况下提交。我在等待响应提交表单后选择输入而不使用它应自动提交的提交按钮(或任何按钮)。
4 个解决方案
#1
4
Make a function to check everything you want has been set, and then if it has, submit the form:
创建一个函数来检查您想要设置的所有内容,如果有,请提交表单:
function submitIfFormComplete()
{
// Check the select has something selected
if (document.getElementById('selectOne').selectedIndex > 0)
{
document.getElementById('formID').submit();
}
}
Then on your select, bind the onchange event to run the function.
然后在您的select上绑定onchange事件以运行该函数。
Here is a working example: http://jsfiddle.net/JE6AM/
这是一个工作示例:http://jsfiddle.net/JE6AM/
Select your car make:
<select id='sel1' name='selectCar' onchange="checkAndSubmit()">
<option value="0">Select...</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<br/><br/>
Select your gender:
<select id='sel2' name='selectGender' onchange="checkAndSubmit()">
<option value="0">Select...</option>
<option value="Male">Volvo</option>
<option value="Female">Saab</option>
</select>
Javascript:
function checkAndSubmit()
{
if (document.getElementById('sel1').selectedIndex > 0
&& document.getElementById('sel2').selectedIndex > 0)
{
//document.getElementById('formID').submit();
alert('both have been selected!');
}
}
I've replaced the submit with an alert() to show you how the code triggers.
我已使用alert()替换了提交,以向您显示代码如何触发。
Edit: You can use $_REQUEST['selectCar']
to access the value.
编辑:您可以使用$ _REQUEST ['selectCar']来访问该值。
#2
4
Every form has a submit()
function.
每个表单都有一个submit()函数。
<form name="myForm">
...
</form>
can be submitted with
可以提交
document.myForm.submit();
#3
0
Jquery has been used to easily to submit the form.
Jquery已经习惯于轻松提交表单。
<form id="test">
<select name="select1" id="select1">
</select>
</form>
$('#select1').change(function() {
$("#test");
});
#4
0
<form action="submit.php" id="submitform" method="post">
Name:<input type="text" name="nm"> <br>
Age:<input type="number" name="age">
<a href="javascript:document.getElementById('submitform').submit()">submit</a>
#1
4
Make a function to check everything you want has been set, and then if it has, submit the form:
创建一个函数来检查您想要设置的所有内容,如果有,请提交表单:
function submitIfFormComplete()
{
// Check the select has something selected
if (document.getElementById('selectOne').selectedIndex > 0)
{
document.getElementById('formID').submit();
}
}
Then on your select, bind the onchange event to run the function.
然后在您的select上绑定onchange事件以运行该函数。
Here is a working example: http://jsfiddle.net/JE6AM/
这是一个工作示例:http://jsfiddle.net/JE6AM/
Select your car make:
<select id='sel1' name='selectCar' onchange="checkAndSubmit()">
<option value="0">Select...</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<br/><br/>
Select your gender:
<select id='sel2' name='selectGender' onchange="checkAndSubmit()">
<option value="0">Select...</option>
<option value="Male">Volvo</option>
<option value="Female">Saab</option>
</select>
Javascript:
function checkAndSubmit()
{
if (document.getElementById('sel1').selectedIndex > 0
&& document.getElementById('sel2').selectedIndex > 0)
{
//document.getElementById('formID').submit();
alert('both have been selected!');
}
}
I've replaced the submit with an alert() to show you how the code triggers.
我已使用alert()替换了提交,以向您显示代码如何触发。
Edit: You can use $_REQUEST['selectCar']
to access the value.
编辑:您可以使用$ _REQUEST ['selectCar']来访问该值。
#2
4
Every form has a submit()
function.
每个表单都有一个submit()函数。
<form name="myForm">
...
</form>
can be submitted with
可以提交
document.myForm.submit();
#3
0
Jquery has been used to easily to submit the form.
Jquery已经习惯于轻松提交表单。
<form id="test">
<select name="select1" id="select1">
</select>
</form>
$('#select1').change(function() {
$("#test");
});
#4
0
<form action="submit.php" id="submitform" method="post">
Name:<input type="text" name="nm"> <br>
Age:<input type="number" name="age">
<a href="javascript:document.getElementById('submitform').submit()">submit</a>