By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,919 Members | 1,096 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,919 IT Pros & Developers. It's quick & easy.

<select> value ?

P: n/a
Hi all ,

I have a script which let the user choose between four days :

Day: <select name=\"day\" value=\"$day\">
<option value=\"01\">1</option>
<option value=\"02\">2</option>
<option value=\"03\">3</option>
<option value=\"04\">4</option>
</select>

The selected number is saved in mysql database.
I have also a script which alows the user to edit their choises.
The problem is that I don't know how to set the value from the database into
the select thingy.

I know how to handel this with an:
<input type="text" name="title" value=$somvar >

But how can I do this with the select thingy ?

thanks !

Oct 16 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Do you want to update all the options again, or do you want to update
just one option ?
Are you using AJAX (read about it on
http://www.nurazije.co.nr/2006/10/5-...-tutorial.html) ?
Please specify more ...

Oct 16 '06 #2

P: n/a
>
But how can I do this with the select thingy ?
Only like this (for example day=03):

<select name=\"day\">
<option value=\"01\">1</option>
<option value=\"02\">2</option>
<option value=\"03\" SELECTED>3</option>
<option value=\"04\">4</option>
</select>

Your option must be SELECTED.

Oct 16 '06 #3

P: n/a
"= poster =" <no****@nomail.spamwrote in message
news:45**********************@news.skynet.be...
Hi all ,

I have a script which let the user choose between four days :

Day: <select name=\"day\" value=\"$day\">
<option value=\"01\">1</option>
<option value=\"02\">2</option>
<option value=\"03\">3</option>
<option value=\"04\">4</option>
</select>

The selected number is saved in mysql database.
I have also a script which alows the user to edit their choises.
The problem is that I don't know how to set the value from the database
into
the select thingy.

I know how to handel this with an:
<input type="text" name="title" value=$somvar >

But how can I do this with the select thingy ?

Just add selected="selected" to the option you want selected.

Example:

<select name=\"day\" value=\"$day\">
<option value=\"01\">1</option>
<option value=\"02\" selected=\"selected\">2</option>
<option value=\"03\">3</option>
<option value=\"04\">4</option>
</select>

this sets 02 selected.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Oct 16 '06 #4

P: n/a
It works !

Thanks !
"Kimmo Laine" <sp**@outolempi.netwrote in message
news:MD*****************@reader1.news.jippii.net.. .
"= poster =" <no****@nomail.spamwrote in message
news:45**********************@news.skynet.be...
>Hi all ,

I have a script which let the user choose between four days :

Day: <select name=\"day\" value=\"$day\">
<option value=\"01\">1</option>
<option value=\"02\">2</option>
<option value=\"03\">3</option>
<option value=\"04\">4</option>
</select>

The selected number is saved in mysql database.
I have also a script which alows the user to edit their choises.
The problem is that I don't know how to set the value from the database
into
the select thingy.

I know how to handel this with an:
<input type="text" name="title" value=$somvar >

But how can I do this with the select thingy ?


Just add selected="selected" to the option you want selected.

Example:

<select name=\"day\" value=\"$day\">
<option value=\"01\">1</option>
<option value=\"02\" selected=\"selected\">2</option>
<option value=\"03\">3</option>
<option value=\"04\">4</option>
</select>

this sets 02 selected.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)

Oct 16 '06 #5

P: n/a
Message-ID: <45**********************@news.skynet.befrom = poster =
contained the following:
>I have also a script which alows the user to edit their choises.
The problem is that I don't know how to set the value from the database into
the select thingy.
I usually use a function to create select boxes, having previously
stored values in an array (either hard coded or taken from a db).

//$array Array of values for the select box e.g.
//$array=array("01"=>"1","02"=>"2","03"=>"3", ...)
//or could come from db
//$name is the name of the select box
//$chosen is current selection taken from $_POST ed value or db

function select($array,$name,$chosen){
$select_box="<select name='$name'>\n";
foreach($array as $key=>$value){
$selected=($key==$chosen)?" selected" : "";
$select_box.=" <option
value='$key'$selected>$value</option>\n";
}
$select_box.="</select>\n";
return $select_box;
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Oct 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.