simon.wilkinson@cohenschemist.co.uk said:
Quote:
>
>Hi,
>
>I am trying to update all Select boxes on a page dynamically using
>javascript, I simple want to change the selected item in each select
>box when a tick box is pressed on the page. Each Select box is named
>in the same convention ie. ddl_DeliveryStatus_ and then the recordID
>and contains the same options in the same order. The number of select
>boxes changes every time the page is loaded as this is all built using
>ASP linked to a database.
>
>I am hoping there is an array or collection or something similar I can
>simply reference to do this, but an struggling to find the answer.
If the select boxes and the checkbox are in the same form,
you can loop through the elements of the form to find all
of the select boxes. I've exceeded your specs by also
preventing the user from changing the select values while
the box is checked:
<html>
<head>
<title>Select Demo</title>
<script type="text/javascript">
function setSelectsToB(box) {
var control=box.form.elements;
for (var i=0;i<control.length;i++) {
if (control[i].type.match(/select/i)) {
if (box.checked) control[i].selectedIndex=1;
control[i].disabled=box.checked;
}
}
}
</script>
<body>
<form>
<select name="alpha"><option>a</option><option>b</option></select><br>
<select name="beta"><option>a</option><option>b</option></select><br>
<select name="gamma"><option>a</option><option>b</option></select><br>
Force to b<input type="checkbox" onclick="setSelectsToB(this)">
</form>
</body>
</html>
--