<OPTION> Tag and Values

C

Craig Keightley

How do I retrive the Name of the item in a select box

I have the following form
<select name="select">
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
</select>

I have a button on the page that i want to alert a message when an item in
the select box has been chosen

eg If Monday was chosen (value 1), the alert should read You selected Monday


Many Thanks

Craig
 
L

Lee

Craig Keightley said:
How do I retrive the Name of the item in a select box

I have the following form
<select name="select">
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
</select>

I have a button on the page that i want to alert a message when an item in
the select box has been chosen

eg If Monday was chosen (value 1), the alert should read You selected Monday

What you're calling the "Name" is the "text" attribute of the
selected option.

So you would use the method describe in the FAQ, but substitute
"text" for "value":
http://www.jibbering.com/faq/#FAQ4_13
 
R

Randy Webb

Craig said:
How do I retrive the Name of the item in a select box

I have the following form
<select name="select">
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
</select>

I have a button on the page that i want to alert a message when an item in
the select box has been chosen

eg If Monday was chosen (value 1), the alert should read You selected Monday

<script type="text/javascript">
function showText(){
el=document.forms['myForm'].elements['mySelect'];

//get the current selections index
elIndex = el.selectedIndex;

//get the current selections text
elText = el.options[elIndex].text;

alert('Since you, as the user, are too stupid, blind or ignorant ' +
'to look at the select list you just changed, I find it, as the ' +
'author, to give you an annoying alert box to let you know you chose ' +
elText)
}
</script>
<form name="myForm">
<select name="mySelect">
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
</select>
<input type="button" onclick="showText()" value="Show Me">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top