简体   繁体   中英

can i submit a form without submit button or without hitting enter?

Can I submit value of <select> in php form without having submit button? In my html/php code I am using two form or we can say two <select> as you can see in coding. In the second <select> (sub category) I want to use value of first <select> (main category) so that it can show me sub category of main <select> . but I am getting confused, how to do this on a single page without using js.

See my code:

<body>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
main course name <select name ="bcate" ><option value=''>choose</option><?php $auth->cmaster_array(); ?></select>
</form>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
sub course name <select name ="sbcate" ><option value=''>select sub course</option><?php $auth->clmaster_array($frsbct); ?></select>
section name <input type="text" name="cname" required/>
remarks <input type="text" name="remarks" required/> 
<input type="submit" name="section_master" value="Submit">
</form>
</body>

You can submit the form using javascript. You can use this code to submit the form

document.getElementById("[ur form id should be here]").submit();

The thing you've asked that , You need value of first select input for second input values.

You can do this only by using jQuery without submitting form.

write change event of first select input box.

then send data to your server by jQuery ajax.

and then fill the second input box received from ajax

Code :

// To get value of select box

$('#select_box_id').change(function() 
{
        var select_box_one_value = $(this).val();
});

$.ajax
({
       type: "POST",
       url: HOST + "/path/to_your_controller_function",
       data: 'data_of_select_box='+select_box_one_value,
       cache: false,
       success: function(msg)
       {
       }
});

using this , your controller will get the value of select box value and then return data from there , and you will receive that data in msg variable.

You can use following code

<form id="jsform" action="whatever you want">
// input fields
</form>

<script type="text/javascript">
  document.getElementById('jsform').submit();
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM