Here's my HTML with PHP:
<form method="post" action="">
<select name="seltemplate" id="seltemplate" style="width:150px" onChange="this.form.submit();">
<option value="0">Select a Template</option>
<?php
// Running the sql query
$query = "SELECT * FROM `stripo_email_templates`";
$rs = mysqli_query($con, $query);
// If at least one record found
if(mysqli_num_rows($rs) > 0)
{
// Fetch table rows
while($row = mysqli_fetch_array($rs))
{
$template_id = $row['template_id'];
$template_name = $row['template_name'];
echo "<option value='$template_id'>$template_name</option>";
}
}
?>
</select>
</form>
I am submitting form using this.form.submit();
without any submit button.
So as soon as select list option is changed, the form is submitted.
After submission of form, I want to receive value of select list selected option.
I am echoing
echo $_POST['seltemplate'];
but no value is received. Why?
this.form.submit()
is not good practice to write in select box element because "this" means select box not form or document for that you try this code.
function select_box_change()
{
var f = document.getElementById('form1');
f.action = "your_php_file";
f.submit();
}
html
<form method="post" id="form1">
<select id="seltemplate" style="width:150px" onChange="select_box_change();">
<option value="0">Select a Template</option>
<option>a</option>
<option>b</option>
</select>
</form>
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.