OnChange, I want to invoke a function that auto populates the rest of the SELECT fields in the form. The select boxes will vary in quantity as the page is dynamic, but the values are always the same (like the code above).
you mean you want to select all of the options when they click the ‘all’?? You need to set some property to allow multiple ones to be selected i believe, unless i misundertood you.
also, it isn’t necessary to name all the options, and if you do you should name them all the same thing.
the number of events that work effectively on selects are few, and way fewer for options, so unless you want to add events to each option, you won’t get a whole lot fancier than this. Assuming what I’ve said above is what you are after, try something like this. Remember, the options of a select object are an array! (just like the checkboxes)
<script language="javascript">
function checkForAll(selObj)
{
if (selObj.options[0].selected)
{
for (var i=1; i<selObj.length; i++)
selObj.options[i].selected = true;
}
}
</script>
<select name="length" onChange="checkForAll(this);" multiple height="4">
<option value="none">--Select for All--</option>
<option value="5">--5 Days--</option>
<option value="7">--7 Days--</option>
<option value="10">--10 Days--</option>
</select>
function lengthfill(){
var lengthField = StageForm.Slength.options[StageForm.Slength.selectedIndex].value;
for (i = 0; i < StageForm.Slength2.length; i++) {
StageForm.Slength2[i].value = lengthField;
}
return true;
}
1) You are hardcoding the DOM names of the FORM and the SELECT into the function. Makes it hard to reuse and/or more editing if anything ever changes.
2) You have two SELECTs in the form with the same DOM name. This is a big no no, and will probably crash most browsers, besides making it impossible to identify just one of them via any DOM structure out there.
Ohhh, I see what you are doing…but I’m not sure why you would want all the values of a select to be the same. Doesn’t that defeat the purpose of having a select?
Correct me if I’m wrong, but you want the runtime data of the selects to look like this (assuming 7 days has been selected)
I’m using this form for a mass data upload to our eBay database. The user is going to fill out the forms and for simplicity’s sake, I wanted to make a checkbox or Select where he could select all values on that page to be the same. That should save him several minutes alone.
As for the DOM naming, I thought about that … I needed an easy way to count the number of boxes checked. So I am using ASP like so
[vbs] intItemCount = Request.Form(“sku”).Count [/vbs]
and looping through the selectde items like this:
[vbs]
for x = 1 to intItemCount
strSKU = Request.Form(“sku”)(x)
if strSKU <> “” then
'get variables
varName = Request.Form(“variable”)(x)