Connecting Tech Pros Worldwide Help | Site Map

Update all select boxes on page using Javascript

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 25th, 2007, 11:45 AM
simon.wilkinson@cohenschemist.co.uk
Guest
 
Posts: n/a
Default Update all select boxes on page using Javascript

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.

Any help would be appreciated.

Thanks

simon


  #2  
Old January 25th, 2007, 02:35 PM
Lee
Guest
 
Posts: n/a
Default Re: Update all select boxes on page using Javascript

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>


--

  #3  
Old January 25th, 2007, 03:05 PM
simon.wilkinson@cohenschemist.co.uk
Guest
 
Posts: n/a
Default Re: Update all select boxes on page using Javascript

Thanks Lee that worked a treat.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.