Click to See Complete Forum and Search --> : selected value from a drop down list


zonome
03-31-2003, 04:01 AM
I have a simple function that displays the value that a user has selected from a drop down list of items:

function DisplayChoice(){
for ( var i = 0; i < document.curveForm.CurrencyList.length; i++){
if ( document.curveForm.CurrencyList.options[i].selected == true){
alert(document.curveForm.CurrencyList.options[i].text);
}
}
}

but for some reason if CurrencyList has more than one element in it the user can not select the first element in the list unless of course they select another element in the list first i.e. if the CurrencyList is A, B, C, D the users have to select B, C or D first before they can select A.

The same applies to a CurencyList that has only one element in it. If the user clicks on the only element then the alert window never pops up on the screen.

Have I done something really stupid in this code?

skriptor
03-31-2003, 04:57 AM
Hi,
code looks good. I think reason is way of calling. I tried this:

<body>
<form name="curveForm">
<input type="button" onclick="DisplayChoice()" value="show">
<select name="CurrencyList">
<option value="a" />A
</select>
</form>

and it works. How do you use your function ?
skriptor

zonome
03-31-2003, 05:57 AM
I have fugured it out.
I need to put an additional entry in the list that is just empty so that when the user selects the next item after the empty entry it will work. kind of like "", firstentry, secondentry, etc

Thanks you fir reading and replying.