Craig Keightley wrote:
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">
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq