Not able to get form element's value after submitting form using this.form.submit();

Sachin

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?

Naresh Vadhavana

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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related