PDA

View Full Version : Change Value from Select Menu Based on the value of a javascript variable



littlemutts
03-30-2006, 10:55 PM
Hi,

I am creating a quoting program for our organisation and need the program to select/change the value which is selected by default in the drop down menu, based on whether another variable on the page is Yes or No.

Is anybody able to help me? This is rather urgent.

Thanks heaps,
Caleb

jscheuer1
03-31-2006, 04:37 AM
There are many ways to access a form element and also many ways to determine the value of a variable and then branch your code depending upon what that value is. I'm assuming that you know which one's that you would like to use. Here is one way of changing the selected option of a drop down:


<select id="sel">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<script type="text/javascript">
document.getElementById('sel').options[3].selected=true
</script>