Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Submit on Select

Tags:

html

php

submit

I am trying to not have a submit button, is there any way that the form can submit when the user selects a value?

<form method="post" action="<?php echo $_SERVER['PHP_SELF']  ?>" >

    <table class="form">

            <select name="category" class="formfield" id="category">
                <option value="-1"> Category </option>
                <?php
                    $sql_contry = "SELECT * FROM category";
                    $rs_c = mysql_query($sql_contry);
                    while ($row_c = mysql_fetch_array($rs_c)) {
                        echo '<option value="'.$row_c['category'].'">'.$row_c['category'].'</option>';  
                    }
                ?>
             </select>

    </table>

</form>
like image 377
Danny Boy Avatar asked Apr 26 '13 19:04

Danny Boy


Video Answer


2 Answers

Here an example

<form>
    <select name='myfield' onchange='this.form.submit()'>
      <option selected>Milk</option>
      <option>Coffee</option>
      <option>Tea</option>
    </select>
    <noscript><input type="submit" value="Submit"></noscript>
</form>

Using noscript tag it allows browsers that are not JavaScript-enabled to still function.

like image 168
TheEwook Avatar answered Oct 06 '22 10:10

TheEwook


Yes - use javascript:

Html:

<form id="frm">
   <select onchange="onSelectChange();">
          <option>1</option>
           <option>1</option>
   <select>
</form>

js:

function onSelectChange(){
 document.getElementById('frm').submit();
}
like image 29
Adidi Avatar answered Oct 06 '22 08:10

Adidi