Page 1 of 1

how to get selected Index of <select> from PHP in java

Posted: Fri Apr 09, 2004 12:30 am
by fadi
hi!
i have a problem. i've populated <select> with a php loop fetching values from database with nId setting its value and its text. now what i want is to get its selected index and its value in javascript to calculate the amount for each item at client side.but prblem i m facing is that javascript gives an error that selectedIndex is null or not an object..can someone help me in this regard. Code is following:
PHP Code:

<?php
print "<select name=MyList onChange=\"return calculateCharges();\">";
print "<option value=''>--Select a Country--</option>";
$queryResult = mysql_query("select regionID, Country from Countries order by Country Asc");

while($eachRow= mysql_fetch_array($queryResult)){

print "<option value='{$eachRow['regionID']}'";
if ($_SESSION['regionID'] == $eachRow['regionID']){
print " selected>";
}
else {
print ">";
}
print "{$eachRow['country']}</option>";
}
print "</select>";
?>
how can i get its selectedIndex value in javascript and calculate the amount for its region..help me.What should i write in calculateCharges() function to set a disabled text value on webpage without sending values to another page.