Robert said:
HI all,
In JS, how can I change the selected value of a dropdownlist(select
options) I know the value of indexed value of the selected value before it
is changed.
Thanks
Robert
Hi Robert,
Just change the value of the OPTION object, like this:
<form name="myFruitsForm" action="bla.php">
<SELECT name="fruit" onChange="changeValue();">
<OPTION value="apple">apple
<OPTION value="orange">orange
<OPTION value="pear">pear
</SELECT>
</form>
<script type="text/javascript">
function changeValue(){
// this function makes juice of your fruit.
var selInd = document.forms["myFruitsForm"].fruit.selectedIndex;
// get the option object
var myOption = document.forms["myFruitsForm"].fruit[selInd];
// and change into fruitjuice:
myOption.value = myOption.value + "juice";
// optionally change the text:
myOption.text = myOption.text + " just juiced!";
}
</script>
Regards,
Erwin Moller