javascript - Submit a form without using submit button -
i using form submit data records database.
in form using 2 select tag options.
so after selecting options form should submit without using submit button. waiting response submit form after selecting inputs without using submit button(or button) should submit automatically.
make function check want has been set, , if has, submit form:
function submitifformcomplete() { // check select has selected if (document.getelementbyid('selectone').selectedindex > 0) { document.getelementbyid('formid').submit(); } }
then on select, bind onchange event run function.
here working example: http://jsfiddle.net/je6am/
select 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 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 submit alert() show how code triggers.
edit: can use $_request['selectcar']
access value.
Comments
Post a Comment