Jump to content

Calling a JS function inside "<option> ? </option> "


Solarpitch

Recommended Posts

Hey,

 

I thought I'd post this one because I will be days trying to sort it!

 

Below I have a simple JS function that changes the properties in a child list box based on the value in the parent list box. I think I need to call the JS function inside the <option> tags of the child list box to get the result I want but I am not sure...

 

snippet..

 


//Variables

var Accessories = new Array("Bag Accessories","Gloves","GPS Devices","Head Covers","Health & Fitness","Other","Practice Aids","Spikes & Wrenches","Tees","Umbrellas");

var Bags = new Array("Carry & Stand Bags","Electric Trolleys","Shoe Bags","Tour Bags","Other");

//function

function oselect(Title)
{


var mselect = window.document.form1.sub_category;
var boxx = eval(Title);
setopt(window.document.form1.sub_category, boxx);
}
function setopt(ychoice, boxx)
{
for (loop=0; loop < ychoice.options.length; loop++)
{
ychoice.options[loop].text = boxx[loop];
}
}

HTML ***************

<select name="category" id="standard_field" "" "" "" <--- Parent 

<select name="sub_category" id="standard_field" onChange="oselect(window.document.form1.category.options[selectedIndex].text);">
                            <option value=><script> setopt(); </script></option></select>

 

When the user clicks an option in "category" it populates the "sub_category" list box with the an array of the defined variables. I can get it to change no problem I just cant get it to calculate the amount of rows the list box will need based on the array.

 

So if Bags is chosen as the category, it will change the sub_category to 5 listed options(rows)...

 

var Bags = new Array("Carry & Stand Bags","Electric Trolleys","Shoe Bags","Tour Bags","Other");

 

 

Hope thats explained ok! :o)

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.