Jump to content

[SOLVED] using variable to get a for id


M.O.S. Studios

Recommended Posts

hey guys,

 

I have drop down menu called country shipping, and thoe other called country billing.

basicly when come one chooses the country the drop down under it fills with states or provinces

 

here is the function i use

 


function ClearOptionsFast(id)
{
var selectObj = document.getElementById(id);
var selectParentNode = selectObj.parentNode;
var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy
selectParentNode.replaceChild(newSelectObj, selectObj);
return newSelectObj;
}

function addOption(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function ChangeDropdowns(value,item_id){
if(value=='CANADA/1/1'){
addOption(document.userprofileform.getElementByName(item_id),'Northwest Territories', 'Nt/1')
addOption(document.userprofileform.getElementByName(item_id),'Newfoundland and Labrador', 'Nl/1')
addOption(document.userprofileform.getElementByName(item_id),'New Brunswick', 'Nb/1')
addOption(document.userprofileform.getElementByName(item_id),'British Columbia', 'Bc/1')
addOption(document.userprofileform.getElementByName(item_id),'Manitoba', 'Mb/1')
addOption(document.userprofileform.getElementByName(item_id),'Alberta', 'Ab/1')

}

here is how its called

 

<select name="ship_con" onChange="ClearOptionsFast('ship_pro'),ChangeDropdowns(this.value,'ship_pro');">
			<option value="CANADA/1/1" SELECTED>CANADA</option>
</select>

 

 

now when i replace the variable 'id_value' with the name of the drop down it works fine, but when i replace it with the variable, it dosn't work, any one see the prob?? thanks in advanced

Link to comment
Share on other sites

im sorry, i posted late last night,

 

the var name is item_id,

when i use the ChangeDropdowns(value,item_id) function,

 

for example, this code works

function ChangeDropdowns(value,item_id){
if(value=='CANADA/1/1'){
addOption(document.userprofileform.ship_pro,'Northwest Territories', 'Nt/1')
}}

 

but i want to replace ship_pro with the variable 'item_id' so that i can control where it put that information with one script. instead of having two scripts that have the exactly the same info just a differn't location

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.