Submit Form When Drop-down List box is Selected

By | August 27, 2012

As like when radio button is clicked, form will be submitted. We can also make auto submit when an item in drop-down list is selected. The purpose of radio button and drop down box is quite simple, both of this html attribute allows us only to select only one option from the given option. Dropdown box will used, when number of options are more and usage of drop-down box will reduce the size of webpage.

Here javascript submit() function is used in onchange event. Onchange of the dropdown box item, the submit function will be triggered.

 
 

Here is the code
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<html>
<body>
<?php
if(isset($_POST['color']))
{
echo "The Color you have selected <b>".$_POST['color']."</b><br><br>";
}
?>
<form action="" method="post">
Select Your Favourite Color:
<select name="color" onchange="javascript: submit()">
<option>---</option>
<option>Red</option>
<option>Blue</option>
<option>White</option>
</select>
</form>
</body>
</html>

 

4 thoughts on “Submit Form When Drop-down List box is Selected

    1. prasad Post author

      give action=”new.php” in first page

      new.php
      if(isset($_POST['color']))
      {
      echo “The Color you have selected “.$_POST['color'];
      }

      Reply
  1. κατασκευη ιστοσελιδων

    great post, very informative. I’m wondering why the opposite
    specialists oof this sector don’t notice this.

    You must proceed your writing. I’m confident, you’ve a great readers’ base already!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

unvitalized-expediency