Submit a form without using submit button

2020-06-25 04:47发布

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条回答
Explosion°爆炸
2楼-- · 2020-06-25 05:15

Jquery has been used to easily to submit the form.

<form id="test">
<select name="select1" id="select1">

</select>
</form>

$('#select1').change(function() {
    $("#test");
});
查看更多
爷、活的狠高调
3楼-- · 2020-06-25 05:18
<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>

查看更多
Fickle 薄情
4楼-- · 2020-06-25 05:29

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.

查看更多
别忘想泡老子
5楼-- · 2020-06-25 05:35

Every form has a submit() function.

<form name="myForm">
...
</form>

can be submitted with

document.myForm.submit();
查看更多
登录 后发表回答