M.O.S. Studios Posted May 28, 2009 Share Posted May 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159996-solved-using-variable-to-get-a-for-id/ Share on other sites More sharing options...
Ken2k7 Posted May 28, 2009 Share Posted May 28, 2009 What variable id_value? What are you talking about? Quote Link to comment https://forums.phpfreaks.com/topic/159996-solved-using-variable-to-get-a-for-id/#findComment-844149 Share on other sites More sharing options...
M.O.S. Studios Posted May 28, 2009 Author Share Posted May 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159996-solved-using-variable-to-get-a-for-id/#findComment-844216 Share on other sites More sharing options...
Ken2k7 Posted May 28, 2009 Share Posted May 28, 2009 function ChangeDropdowns(value,item_id){ if(value=='CANADA/1/1'){ addOption(document.forms.userprofileform[item_id],'Northwest Territories', 'Nt/1') }} Quote Link to comment https://forums.phpfreaks.com/topic/159996-solved-using-variable-to-get-a-for-id/#findComment-844223 Share on other sites More sharing options...
M.O.S. Studios Posted May 28, 2009 Author Share Posted May 28, 2009 as always the phpfreak fourms are a life saver, worked like a charm thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/159996-solved-using-variable-to-get-a-for-id/#findComment-844229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.