Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the Value of All Drop Down Menus with One Click

Status
Not open for further replies.

deharris2003

Programmer
Jul 1, 2003
41
US
Does anyone know of a script that will change the value of all Drop Down Menus when the User Selects a Change All Button?
 
It's be easy enough to develop one, but you leave out several details...

Most importantly, with what information will the drop-down be updated? Form text boxes or merely some set of default values that doesn't change?

--Dave
 
Well My current Page pulls records from a Database. The total amount of Drop Down Boxes will differ based on the Recordset Results. All Boxes are Named accordingly with D & intCount (Where intCount = the Numerical value of that box). Each Drop Down has only two Values to select from. All the Boxes are defaulted with an employees name. THe only other option to select is "None". The Purpose of this form is to allow the end-user the ability to clear out records that have been assigned to them. If the User Selects "None" Then That Record is put back in the pot for another user to select from. The goal is to give the Employee the Option to say "Clear ALL" which will set all drop downs to "None". Eventually I wanted to give the user the Ability to Select "Clear ALL" and have them enter in a seperate box their Name. Then the script would re-set all values where there name is selected or it WOuld Clear All Values if the Word All was inputed in the second box.
 
This only addresses your first concern: using a Clear All button.

If all your drop downs have the same id, you can do the following:

Code:
<HTML
<HEAD>
<SCRIPT>
var dropdowns;
function collectDDs()
{
 dropdowns = getElementsByName(&quot;ddowns&quot;);
}

function clearAll()
{
 for(i=0; i<dropdowns.length; i++)
 {
  dropdowns[i].selectedIndex = 0;
 }
}
</SCRIPT>
</HEAD>
<BODY onLoad=collectDDs()>
<SELECT NAME=D1 ID=ddowns>
<OPTION VALUE=NONE>None
<OPTION VALUE=WHATEVER>Whatever
</SELECT>
...
<INPUT TYPE=BUTTON VALUE='Clear All' onClick=clearAll()>
</BODY>
</HTML>

The above assumes that None is the first option in every drop down. Yes, using getElementsByName seems to work when you name an id value. I know this seems odd, but it has worked for me.

'hope this helped.

--Dave
 
I appreciate all your help but I pasted your code into a blank document and was unable to get it to work. I am not sure why it doesn't work I am new to Javascript but what you wrote seems logical.
 
This is just a guess but the function ClearAll refers to an array called dropdowns. dropdowns is defined in the function CollectDDs but is not defined as an array. If this correct I do not know how to fix it. your help is much appreciated
 
->
[tt]
function collectDDs()
{
dropdowns = getElementsByName(&quot;ddowns&quot;);
}
..
<SELECT NAME=D1 ID=ddowns>
[/tt]

you identify the dropdown with an ID of &quot;ddowns&quot;, then try and match it using getElementsByName. you could try:
Code:
function collectDDs()
{
 dropdowns = getElementsByID(&quot;ddowns&quot;);
}
..
<select name=&quot;D1&quot; id=&quot;ddowns&quot;>
...



Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
If it is an array problem, then when you declare var dropdowns, write instead:

Code:
var dropdowns = new Array();

In fact, I think that might be necessary. I did not test it out and sometimes have to work my way through use of arrays by trial and error.

Good luck.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top