PDA

View Full Version : Drop box properties


shady
12-20-2002, 09:46 AM
I have a HTML drop down list called "Supplier", I am trying to pass the drop box selection into a java variable so that I can test to see what is contained in the box, and then perform operations based on a selection. What is the correct syntax for obtaining the selection made? I have tried:-

MyVar = document.Supplier.text.value

MyVar = document.Supplier.option.value

but to no avail, could someone enlighten me

Regards

Shady

Ökii
12-20-2002, 10:10 AM
<form name="myform" .........>
<select name="myselect" ........>


var = document.forms['myform'].elements['myselect'].value;

shady
12-20-2002, 10:58 AM
I have altered my code as you advised, here is what I have:-

function calculation()
{
mySupplier = document.forms['myForm'].elements['supplier'].value;

switch (mySupplier)

{
case "Amerada" :
alert("Amerada");
break;

case "Bizz Energy" :
alert("Bizz Energy");
break;

default :
alert(mySupplier);
break;
}

}

now whilst there is no error message anymore, the variable does not seem to contain the text selected from the drop box list, the result of this function is that the default code is always executed, but the alert which should give me the name of the supplier always displays a blank box.

Any ideas???

Regards

Shady

Tanker
12-20-2002, 06:58 PM
something like this?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Dropdown Values</title>
<script language="JavaScript1.2">
<!--
function checkSup(supp){
switch(supp){
case "1" :
alert("You have chosen Supplier number 1");
break;
case "2" :
alert("You have chosen Supplier number 2");
break;
case "3" :
alert("You have chosen Supplier number 3");
break;
case "4" :
alert("You have chosen Supplier number 4");
break;
default :
alert("There was an error in your choice of suppliers, Please try again")
}
}
//-->
</script>
</head>

<body>
<form action="" name="myForm" id="myForm">
<select name="suppliers" size="1" onChange="checkSup(this.options[selectedIndex].value);">
<option value="" SELECTED></option>
<option value="1">Supplier 1</option>
<option value="2">Supplier 2</option>
<option value="3">Supplier 3</option>
<option value="4">Supplier 4</option>
</select>
</form>
</body>
</html>

RadarBob
12-21-2002, 12:51 AM
<script>
function checkSup (theDropdown) {
var theIndex = theDropdown.options.selectedIndex;
var theValue = theDropdown.options[theindex].value;
. . .
}
</script>
. . .

<select name="suppliers" size="1" onChange="checkSup(this);">