tags:

views:

30

answers:

3

How to specify each option at a select tag?,using which attribute (name,id,....)? and how to recieve it in the server script to detect which option is selected?

+1  A: 

The index in $_GET or $_POST will be the name of the select tag. The contents of the array element will be the value of the option.

Ignacio Vazquez-Abrams
or if the value isn't specified, the text after each option tag
Byron Whitlock
-1 for the missing example code ... which should IMHO always be present in an answer to a newbie question
vog
A: 

You use this:

<select name="select1">
  <option value="val1">Option 1</option>
  <option value="val2">Option 2</option>
</select>

As for the server side, it depends on which technology you are using.

edit sorry I didn't see you tagged it as php. $_POST or $_GET will contain the "select1" item, depending on which method you're using in your form tag.

cambraca
+1  A: 

Here's a standard select box, in which value and content are different:

<select name="color_id">
  <option value="1">Red</option>
  <option value="2">Blue</option>
  <option value="3">Green</option>
</select>

Upon form submission, $_GET['color_id'] or $_POST['color_id'] (depending on the form method) would be set to 2 if the user had selected Blue.

If the content of the option is the value you want to send, no need to repeat yourself; the option's value is set to the content if no other value is specified.

<select name="color_id">
  <option>Red</option>
  <option>Blue</option>
  <option>Green</option>
</select>

Upon form submission, $_GET['color_id'] or $_POST['color_id'] (depending on the form method) would be set to Blue if the user had selected Blue.

Matchu
@vog: I caught it before you refreshed ;) Thanks!
Matchu