473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

<select> value ?

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
5 2223
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
>
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
"= 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
7
by: Hal Vaughan | last post by:
I have a sample script from a book ("Beginning JavaScript" by Paul Wilton) that removes or adds a choice to a <SELECT> element. The <FORM> is form1 and the <SELECT> is theDay. The example uses...
1
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php...
7
by: Felix Natter | last post by:
hi, I have a php-Script which gets passed a Boat-ID and this is used to mark an element in a <select> as the default: <select name="boote" multiple="multiple" size="5"> <option...
6
by: Omar | last post by:
Hi, In a JSP I have the next: .... codigo = "<select name='" + nombre + "'>\n<option selected value='default'>Escoge</option><option value='todos'>Todos</option>"; if (miRS != null) while...
6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
1
by: frey | last post by:
i tried to create a dropdown menu and use the option as a control to change content inside another text area the code is like this: <select name="xxxx"><option onclick="changeunitprice(29.87)"...
4
by: luftikus143 | last post by:
Hi there, I have a nasty little problem, as so often, only with IE. Here is an screenshot to better illustrate the problem. http://geodata.grid.unep.ch/screenshot13.png The map is clickable (to...
2
by: msg2ajay | last post by:
hi all, I have a problem with <html:select> i am getting a value from the database but it is not setting to my <select value>. Can any bady tellme what is the problem. My code is given...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.