/    Sign up×
Community /Pin to ProfileBookmark

Need help with Form

Ok, i’m a graphics designer for a company and they’re getting me to start doing web sites for them… i have to make a order form and they want the state field to hide if the country is not usa or canada. i have been trying for hours to use a script i found. It works fine when i only have a couple countries, but as soon as i tried the whole list, it stopped working, the fields dont return anything at all.. Anyways, i’m struggling to get this thing to work right and it’s stressing me that i cant find the problem. Besides the fact that i have to get it to my boss as soon as possible.

I tried contacting the creater of the script but i havnt gotten a e-mail and i’m in a rush to get this done thanks to anyone who atleast takes time to look at all this crap lol

This is the main code chainedselects.js

[code=html][FORM][INPUT TYPE=”textarea”]
// Chained Selects

// Copyright Xin Yang 2004
// Web Site: www.yxScripts.com
// EMail: [email protected]
// Last Updated: 2004-08-23

// This script is free as long as the copyright notice remains intact.

var _disable_empty_list=false;
var _hide_empty_list=false;

// ——
if (typeof(disable_empty_list)==”undefined”) { disable_empty_list=_disable_empty_list; }
if (typeof(hide_empty_list)==”undefined”) { hide_empty_list=_hide_empty_list; }

var cs_goodContent=true, cs_M=”M”, cs_L=”L”, cs_curTop=null, cs_curSub=null;

function cs_findOBJ(obj,n) {
for (var i=0; i<obj.length; i++) {
if (obj[i].name==n) { return obj[i]; }
}
return null;
}
function cs_findContent(n) { return cs_findOBJ(cs_content,n); }

function cs_findM(m,n) {
if (m.name==n) { return m; }

var sm=null;
for (var i=0; i<m.items.length; i++) {
if (m.items[i].type==cs_M) {
sm=cs_findM(m.items[i],n);
if (sm!=null) { break; }
}
}
return sm;
}
function cs_findMenu(n) { return (cs_curSub!=null && cs_curSub.name==n)?cs_curSub:cs_findM(cs_curTop,n); }

function cs_contentOBJ(n,obj){ this.name=n; this.menu=obj; this.lists=new Array(); this.cookie=””; }; cs_content=new Array();
function cs_topmenuOBJ(tm) { this.name=tm; this.items=new Array(); this.df=0; this.addM=cs_addM; this.addL=cs_addL; }
function cs_submenuOBJ(dis,link,sub) {
this.name=sub;
this.type=cs_M; this.dis=dis; this.link=link; this.df=0;

var x=cs_findMenu(sub);
this.items=x==null?new Array():x.items;

this.addM=cs_addM; this.addL=cs_addL;
}
function cs_linkOBJ(dis,link) { this.type=cs_L; this.dis=dis; this.link=link; }

function cs_addM(dis,link,sub) { this.items[this.items.length]=new cs_submenuOBJ(dis,link,sub); }
function cs_addL(dis,link) { this.items[this.items.length]=new cs_linkOBJ(dis,link); }

function cs_showMsg(msg) { window.status=msg; }
function cs_badContent(n) { cs_goodContent=false; cs_showMsg(“[“+n+”] Not Found.”); }

function cs_optionOBJ(text,value) { this.text=text; this.value=value; }
function cs_emptyList(list) { for (var i=list.options.length-1; i>=0; i–) { list.options[i]=null; } }
function cs_refreshList(list,opt,df) {
cs_emptyList(list);

for (var i=0; i<opt.length; i++) {
list.options[i]=new Option(opt[i].text, opt[i].value);
}

if (opt.length>0) {
list.selectedIndex=df;
}
}
function cs_getOptions(menu) {
var opt=new Array();
for (var i=0; i<menu.items.length; i++) {
opt[i]=new cs_optionOBJ(menu.items[i].dis, menu.items[i].link);
}
return opt;
}
function cs_updateListGroup(content,idx,sidx,mode) {
var i=0, curItem=null, menu=content.menu;

while (i<idx) {
menu=menu.items[content.lists[i++].selectedIndex];
}

if (menu.items[sidx].type==cs_M && idx<content.lists.length-1) {
var df=cs_getIdx(mode,content.cookie,idx+1,menu.items[sidx].df);

cs_refreshList(content.lists[idx+1], cs_getOptions(menu.items[sidx]), df);
if (content.cookie) {
cs_setCookie(content.cookie+”_”+(idx+1),df);
}

if (idx+1<content.lists.length) {
if (disable_empty_list) {
content.lists[idx+1].disabled=false;
}
if (hide_empty_list) {
content.lists[idx+1].style.display=””;
}

cs_updateListGroup(content,idx+1,df,mode);
}
}
else {
for (var s=idx+1; s<content.lists.length; s++) {
cs_emptyList(content.lists[s]);

if (disable_empty_list) {
content.lists[s].disabled=true;
}
if (hide_empty_list) {
content.lists[s].style.display=”none”;
}

if (content.cookie) {
cs_setCookie(content.cookie+”_”+s,””);
}
}
}
}
function cs_initListGroup(content,mode) {
var df=cs_getIdx(mode,content.cookie,0,content.menu.df);

cs_refreshList(content.lists[0], cs_getOptions(content.menu), df);
if (content.cookie) {
cs_setCookie(content.cookie+”_”+0,df);
}

cs_updateListGroup(content,0,df,mode);
}

function cs_updateList() {
var content=this.content;
for (var i=0; i<content.lists.length; i++) {
if (content.lists[i]==this) {
if (content.cookie) {
cs_setCookie(content.cookie+”_”+i,this.selectedIndex);
}

if (i<content.lists.length-1) {
cs_updateListGroup(content,i,this.selectedIndex,””);
}
}
}
}

function cs_getIdx(mode,name,idx,df) {
if (mode) {
var cs_idx=cs_getCookie(name+”_”+idx);
if (cs_idx!=””) {
df=parseInt(cs_idx);
}
}
return df;
}

function _setCookie(name, value) {
document.cookie=name+”=”+value;
}
function cs_setCookie(name, value) {
setTimeout(“_setCookie(‘”+name+”‘,'”+value+”‘)”,0);
}

function cs_getCookie(name) {
var cookieRE=new RegExp(name+”=([^;]+)”);
if (document.cookie.search(cookieRE)!=-1) {
return RegExp.$1;
}
else {
return “”;
}
}

// —-
function addListGroup(n,tm) {
if (cs_goodContent) {
cs_curTop=new cs_topmenuOBJ(tm); cs_curSub=null;

var c=cs_findContent(n);
if (c==null) {
cs_content[cs_content.length]=new cs_contentOBJ(n,cs_curTop);
}
else {
delete(c.menu); c.menu=cs_curTop;
}
}
}

function addList(n,dis,link,sub,df) {
if (cs_goodContent) {
cs_curSub=cs_findMenu(n);

if (cs_curSub!=null) {
cs_curSub.addM(dis,link||””,sub);
if (typeof(df)!=”undefined”) { cs_curSub.df=cs_curSub.items.length-1; }
}
else {
cs_badContent(n);
}
}
}

function addOption(n,dis,link,df) {
if (cs_goodContent) {
cs_curSub=cs_findMenu(n);

if (cs_curSub!=null) {
cs_curSub.addL(dis,link||””);
if (typeof(df)!=”undefined”) { cs_curSub.df=cs_curSub.items.length-1; }
}
else {
cs_badContent(n);
}
}
}

function initListGroup(n) {
var _content=cs_findContent(n), count=0;
if (_content!=null) {
content=new cs_contentOBJ(“cs_”+n,_content.menu);
cs_content[cs_content.length]=content;

for (var i=1; i<initListGroup.arguments.length; i++) {
if (typeof(arguments[i])==”object” && arguments[i].tagName && arguments[i].tagName==”SELECT”) {
content.lists[count]=arguments[i];

arguments[i].onchange=cs_updateList;
arguments[i].content=content; arguments[i].idx=count++;
}
else if (typeof(arguments[i])==”string” && /^[a-zA-Z_]w*$/.test(arguments[i])) {
content.cookie=arguments[i];
}
}

if (content.lists.length>0) {
cs_initListGroup(content,content.cookie);
}
}
}

function resetListGroup(n) {
var content=cs_findContent(“cs_”+n);
if (content!=null && content.lists.length>0) {
cs_initListGroup(content,””);
}
}
// ——
[/INPUT][/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 20.2007 — Can you give the full document or preferably a link?
Copy linkTweet thisAlerts:
@AmonCronzauthorOct 20.2007 — This is the script for the lists config.js


[code=html]//var hide_empty_list=true; //uncomment this line to hide empty selection lists
var disable_empty_list=true; //uncomment this line to disable empty selection lists

addOptionGroup("country", "location");
addOption("location", "Select a country","","none");
addList("location", "United States", "UnitedStates", "unitedstates" 1);
addOption("unitedstates", "Select a state", "");
addOption("unitedstates", "Alabama", "Alabama");
addOption("unitedstates", "Alaska", "Alaska");
addOption("unitedstates", "Arizona", "Arizona");
addOption("unitedstates", "Arkansas", "Arkansas");
addOption("unitedstates", "California", "California");
addOption("unitedstates", "Colorado", "Colorado");
addOption("unitedstates", "Connecticut", "Connecticut");
addOption("unitedstates", "Delaware", "Delaware");
addOption("unitedstates", "Florida", "Florida");
addOption("unitedstates", "Georgia", "Georgia");
addOption("unitedstates", "Hawaii", "Hawaii");
addOption("unitedstates", "Idaho", "Idaho");
addOption("unitedstates", "Illinois", "Illinois");
addOption("unitedstates", "Indiana", "Indiana");
addOption("unitedstates", "Iowa", "Iowa");
addOption("unitedstates", "Kansas", "Kansas");
addOption("unitedstates", "Kentucky", "Kentucky");
addOption("unitedstates", "Louisiana", "Louisiana");
addOption("unitedstates", "Maine", "Maine");
addOption("unitedstates", "Maryland", "Maryland");
addOption("unitedstates", "Massachusetts", "Massachusetts");
addOption("unitedstates", "Michigan", "Michigan");
addOption("unitedstates", "Minnesota", "Minnesota");
addOption("unitedstates", "Mississippi", "Mississippi");
addOption("unitedstates", "Missouri", "Missouri");
addOption("unitedstates", "Montana", "Montana");
addOption("unitedstates", "Nebraska", "Nebraska");
addOption("unitedstates", "Nevada", "Nevada");
addOption("unitedstates", "New Hampshire", "NewHampshire");
addOption("unitedstates", "New Jersey", "NewJersey");
addOption("unitedstates", "New Mexico", "NewMexico");
addOption("unitedstates", "New York", "NewYork");
addOption("unitedstates", "North Carolina", "NorthCarolina");
addOption("unitedstates", "North Dakota", "NorthDakota");
addOption("unitedstates", "Ohio", "Ohio");
addOption("unitedstates", "Oklahoma", "Oklahoma");
addOption("unitedstates", "Oregon", "Oregon");
addOption("unitedstates", "Pennsylvania", "Pennsylvania");
addOption("unitedstates", "Rhode Island", "RhodeIsland");
addOption("unitedstates", "South Carolina", "SouthCarolina");
addOption("unitedstates", "South Dakota", "SouthDakota");
addOption("unitedstates", "Tennessee", "Tennessee");
addOption("unitedstates", "Texas", "Texas");
addOption("unitedstates", "Utah", "Utah");
addOption("unitedstates", "Vermont", "Vermont");
addOption("unitedstates", "Virginia", "Virginia");
addOption("unitedstates", "Washington", "Washington");
addOption("unitedstates", "West Virginia", "WestVirginia");
addOption("unitedstates", "Wisconsin", "Wisconsin");
addOption("unitedstates", "Wyoming", "Wyoming");
addList("location", "Albania", "Albania","none");
addList("location", "Angolia", "Angolia","none");
addList("location", "Antigua", "Antigua","none");
addList("location", "Argentina", "Argentina","none");
addList("location", "Armenia", "Armenia","none");
addList("location", "Aruba", "Aruba","none");
addList("location", "Australia", "Australia","none");
addList("location", "Austria", "Austria","none");
addList("location", "Bahamas", "Bahamas","none");
addList("location", "Bahrain", "Bahrain","none");
addList("location", "Barbados", "Barbados","none");
addList("location", "Belarus", "Belarus","none");
addList("location", "Belgium", "Belgium","none");
addList("location", "Belize", "Belize","none");
addList("location", "Bermuda", "Bermuda","none");
addList("location", "Bolivia", "Bolivia","none");
addList("location", "Bosnia","Bosnia","none");
addList("location", "Brazil", "Brazil","none");
addList("location", "Bulgaria", "Bulgaria","none");
addList("location", "Burma", "Burma","none");
addList("location", "Canada", "Canada","none");
addList("location", "Chile", "Chile","none");
addList("location", "China", "China","none");
addList("location", "Columbia", "Columbia","none");
addList("location", "Costa Rica", "CostaRica","none");
addList("location", "Croatia", "Croatia","none");
addList("location", "Cuba", "Cuba","none");
addList("location", "Cyprus", "Cyprus","none");
addList("location", "Czech Republic", "CzechRepublic","none");
addList("location", "Denmark", "Denmark","none");
addList("location", "Dominican Republic", "DominicanRepublic","none");
addList("location", "Ecuador", "Ecuador","none");
addList("location", "Egypt", "Egypt","none");
addList("location", "El Salvador", "ElSalvador","none");
addList("location", "England", "England","none");
addList("location", "Estonia", "Estonia","none");
addList("location", "Fiji", "Fiji","none");
addList("location", "Finland", "Finland","none");
addList("location", "France", "France");
addList("location", "French Polynesia", "FrenchPolynesia","none");
addList("location", "Georgia", "Georgia","none");
addList("location", "Germany", "Germany","none");
addList("location", "Ghana", "Ghana","none");
addList("location", "Greece", "Greece","none");
addList("location", "Guam", "Guam");
addList("location", "Guatemala", "Guatemala","none");
addList("location", "Haiti", "Haiti","none");
addList("location", "Honduras", "Honduras","none");
addList("location", "Hong Kong", "HongKong","none");
addList("location", "Hungary", "Hungary","none");
addList("location", "Iceland", "Iceland","none");
addList("location", "India", "India","none");
addList("location", "Indonesia", "Indonesia","none");
addList("location", "International", "International","none");
addList("location", "Iran", "Iran","none");
addList("location", "Ireland", "Ireland","none");
addList("location", "Israel", "Israel","none");
addList("location", "Italy", "Italy","none");
addList("location", "Jamaica", "Jamaica","none");
addList("location", "Japan", "Japan","none");
addList("location", "Jordan", "Jordan","none");
addList("location", "Kenya", "Kenya","none");
addList("location", "Korea", "Korea","none");
addList("location", "Kuwait", "Kuwait","none");
addList("location", "Latvia", "Latvia","none");
addList("location", "Lebanon", "Lebanon","none");
addList("location", "Liechtenstein", "Liechtenstein","none");
addList("location", "Lithuania", "Lithuania","none");
addList("location", "Luxembourg", "Luxembourg","none");
addList("location", "Macedonia", "Macedonia","none");
addList("location", "Malaysia", "Malaysia","none");
addList("location", "Malta", "Malta","none");
addList("location", "Mauritius", "Mauritius","none");
addList("location", "Mexico", "Mexico","none");
addList("location", "Moldova", "Moldova","none");
addList("location", "Monaco", "Monaco","none");
addList("location", "Morocco", "Morocco","none");
addList("location", "Myanmar", "Myanmar","none");
addList("location", "Netherlands", "Netherlands","none");
addList("location", "Netherlands Antilles", "NetherlandsAntilles","none");
addList("location", "New Zealand", "NewZealand","none");
addList("location", "Nicaragua", "Nicaragua","none");
addList("location", "Nigeria", "Nigeria","none");
addList("location", "Norway", "Norway","none");
addList("location", "Pakistan", "Pakistan","none");
addList("location", "Panama", "Panama","none");
addList("location", "Paraguay", "Paraguay","none");
addList("location", "Peru", "Peru","none");
addList("location", "Philippines", "Philippines","none");
addList("location", "Poland", "Poland","none");
addList("location", "Portugal", "Portugal","none");
addList("location", "Puerto Rico", "PuertoRico","none");
addList("location", "Qatar", "Qatar","none");
addList("location", "Romania", "Romania","none");
addList("location", "Russia", "Russia","none");
addList("location", "Saipan", "Saipan","none");
addList("location", "Saudi Arabia", "SaudiArabia","none");
addList("location", "Scotland", "Scotland","none");
addList("location", "Singapore", "Singapore","none");
addList("location", "Slovakia", "Slovakia","none");
addList("location", "Slovenia", "Slovenia","none");
addList("location", "South Africa", "SouthAfrica","none");
addList("location", "Spain", "Spain","none");
addList("location", "Sweden", "Sweden","none");
addList("location", "Switzerland", "Switzerland","none");
addList("location", "Taiwan", "Taiwan","none");
addList("location", "Thailand", "Thailand","none");
addList("location", "Trinidad", "Trinidad","none");
addList("location", "Turkey", "Turkey","none");
addList("location", "Uganda", "Uganda","none");
addList("location", "Ukraine", "Ukraine","none");
addList("location", "United Arab Emirates", "UnitedArabEmirates","none");
addList("location", "United Kingdom", "UnitedKingdom","none");
addList("location", "Uruguay", "Uruguay","none");
addList("location", "Uzbekistan", "Uzbekistan","none");
addList("location", "Vatican", "Vatican","none");
addList("location", "Venezuela", "Venezuela","none");
addList("location", "Vietnam", "Vietnam","none");
addList("location", "Virgin Islands", "VirginIslands","none");
addList("location", "Yugoslavia", "Yugoslavia","none");

addOption("none", "Not available");


[/code]
Copy linkTweet thisAlerts:
@AmonCronzauthorOct 20.2007 — and finally the html file

[code=html][INPUT type="textarea"]<html>

<head>
<title>Chained Selects</title>

<script language="javascript" src="chainedselects.js">

/***********************************************
* Chained Selects script- By Xin Yang (http://www.yxscripts.com/)
* Script featured on/available at http://www.dynamicdrive.com/
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>
<script language="javascript" src="config.js"></script>

</head>

<body onload="initListGroup('country', document.forms[0].countr, document.forms[0].state, 'save')">

<table align="center" cellpadding="0" cellspacing="0" border="0" width="90%"><tr><td>
<h3 align="center">Chained Selects</h3>
<p align="center" class="copyright">Copyright 2004&nbsp;&nbsp;&nbsp;&nbsp;Xin Yang</p>

<form>
<table align="center"><tr>
<td>Country:&nbsp;</td>
<td><select name="countr" style="width:250px;"></select></td>
<td><select name="state" style="width:250px;"></select></td>
<td></td>
<td><input type="button" value="Reset" onclick="resetListGroup('country')">
</tr></table>
</form>

</body>

</html>
[/INPUT][/code]
Copy linkTweet thisAlerts:
@FangOct 21.2007 — &lt;select name="countr" style="width:250px;" [COLOR="Green"]onchange="form.state.disabled=(this.value=='unitedstates' || this.value=='canada')? false : true;"[/COLOR]&gt;
×

Success!

Help @AmonCronz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...