Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  151] [ 7]  / answers: 1 / hits: 36134  / 11 Years ago, mon, july 22, 2013, 12:00:00

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.


More From » forms

 Answers
48

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.



Here is a working example: 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.



Edit: You can use $_REQUEST['selectCar'] to access the value.


[#76828] Sunday, July 21, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
samarab

Total Points: 620
Total Questions: 95
Total Answers: 89

Location: Bonaire
Member since Wed, May 11, 2022
2 Years ago
;