/    Sign up×
Community /Pin to ProfileBookmark

HELP: Need this form code to work

I have been trying to get this select form element to work properly for two weeks, so that I can post my form. I’ve been using dreamweaver and a bit of html to develop a form. I don’t know javascript and what I have learned has only confused me more.

I have taken a pre-existing (SEE Below) and I have tried to alterate to suit my needs. I would have liked to use the first element to have state names, and the second element to have city and then hotels. I don’t need an “other” option because there are no other choices. The code works initially but if I make changes to it it no longer works. Can anyone help me try to figure this out.

ORIGINAL CODE
<HEAD>
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
var africaArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Ethiopia’)”,
“(‘Somalia’)”,
“(‘South Africa’)”,
“(‘Other’)”);
var middleeastArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Egypt’)”,
“(‘Iran’)”,
“(‘Israel’)”,
“(‘Kuwait’)”,
“(‘Lebanon’)”,
“(‘Morocco’)”,
“(‘Saudi Arabia’)”,
“(‘Syria’)”,
“(‘Turkey’)”,
“(‘U. A. Emirates’)”,
“(‘Other’)”);
var asiaArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Armenia’)”,
“(‘Bangladesh’)”,
“(‘Cambodia’)”,
“(‘China’)”,
“(‘India’)”,
“(‘Indonesia’)”,
“(‘Japan’)”,
“(‘Malaysia’)”,
“(‘Myanmar’)”,
“(‘Nepal’)”,
“(‘Pakistan’)”,
“(‘Philippines’)”,
“(‘Singapore’)”,
“(‘South Korea’)”,
“(‘Sri Lanka’)”,
“(‘Taiwan’)”,
“(‘Thailand’)”,
“(‘Uzbekistan’)”,
“(‘Vietnam’)”,
“(‘Other’)”);
var europeArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Albania’)”,
“(‘Austria’)”,
“(‘Belarus’)”,
“(‘Belgium’)”,
“(‘Bosnia’)”,
“(‘Bulgaria’)”,
“(‘Croatia’)”,
“(‘Cyprus’)”,
“(‘Czech Rep.’)”,
“(‘Denmark’)”,
“(‘Estonia’)”,
“(‘Finland’)”,
“(‘France’)”,
“(‘Germany’)”,
“(‘Greece’)”,
“(‘Hungary’)”,
“(‘Iceland’)”,
“(‘Ireland’)”,
“(‘Italy’)”,
“(‘Latvia’)”,
“(‘Liechtenstein’)”,
“(‘Lithuania’)”,
“(‘Luxembourg’)”,
“(‘Macedonia’)”,
“(‘Malta’)”,
“(‘Monaco’)”,
“(‘Netherlands’)”,
“(‘Norway’)”,
“(‘Poland’)”,
“(‘Portugal’)”,
“(‘Romania’)”,
“(‘Russia’)”,
“(‘Slovakia’)”,
“(‘Slovenia’)”,
“(‘Spain’)”,
“(‘Sweden’)”,
“(‘Switzerland’)”,
“(‘Ukraine’)”,
“(‘United Kingdom’)”,
“(‘Other’)”);
var australiaArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Australia’)”,
“(‘New Zealand’)”,
“(‘Other’)”);
var lamericaArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Costa Rica’)”,
“(‘Cuba’)”,
“(‘El Salvador’)”,
“(‘Guatemala’)”,
“(‘Haiti’)”,
“(‘Jamaica’)”,
“(‘Mexico’)”,
“(‘Panama’)”,
“(‘Other’)”);
var namericaArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Canada’)”,
“(‘USA’)”,
“(‘Other’)”);
var samericaArray = new Array(“(‘Select country’,”,true,true)”,
“(‘Argentina’)”,
“(‘Bolivia’)”,
“(‘Brazil’)”,
“(‘Chile’)”,
“(‘Colombia’)”,
“(‘Ecuador’)”,
“(‘Paraguay’)”,
“(‘Peru’)”,
“(‘Suriname’)”,
“(‘Uruguay’)”,
“(‘Venezuela’)”,
“(‘Other’)”);
function populateCountry(inForm,selected) {
var selectedArray = eval(selected + “Array”);
while (selectedArray.length < inForm.country.options.length) {
inForm.country.options[(inForm.country.options.length – 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval(“inForm.country.options[i]=” + “new Option” + selectedArray[i]);
}
if (inForm.region.options[0].value == ”) {
inForm.region.options[0]= null;
if ( navigator.appName == ‘Netscape’) {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == ‘Win32’ || navigator.platform == ‘Win16’) {
window.history.go(0);
}
}
}
}
}
function populateUSstate(inForm,selected) {

var stateArray = new Array(“(‘Select State’,”,true,true)”,
“(‘Alabama’)”,
“(‘Alaska’)”,
“(‘Arizona’)”,
“(‘Arkansas’)”,
“(‘California’)”,
“(‘Colorado’)”,
“(‘Connecticut’)”,
“(‘Delaware’)”,
“(‘Columbia’)”,
“(‘Florida’)”,
“(‘Georgia’)”,
“(‘Hawaii’)”,
“(‘Idaho’)”,
“(‘Illinois’)”,
“(‘Indiana’)”,
“(‘Iowa’)”,
“(‘Kansas’)”,
“(‘Kentucky’)”,
“(‘Louisiana’)”,
“(‘Maine’)”,
“(‘Maryland’)”,
“(‘Massachusetts’)”,
“(‘Michigan’)”,
“(‘Minnesota’)”,
“(‘Mississippi’)”,
“(‘Missouri’)”,
“(‘Montana’)”,
“(‘Nebraska’)”,
“(‘Nevada’)”,
“(‘New Hampshire’)”,
“(‘New Jersey’)”,
“(‘New Mexico’)”,
“(‘New York’)”,
“(‘North Carolina’)”,
“(‘North Dakota’)”,
“(‘Ohio’)”,
“(‘Oklahoma’)”,
“(‘Oregon’)”,
“(‘Pennsylvania’)”,
“(‘Rhode Island’)”,
“(‘South Carolina’)”,
“(‘South Dakota’)”,
“(‘Tennessee’)”,
“(‘Texas’)”,
“(‘Utah’)”,
“(‘Vermont’)”,
“(‘Virginia’)”,
“(‘Washington’)”,
“(‘West Virginia’)”,
“(‘Wisconsin’)”,
“(‘Wyoming’)”);
if (selected == ‘USA’) {
for (var i=0; i < stateArray.length; i++) {
eval(“inForm.country.options[i]=” + “new Option” + stateArray[i]);
}
if ( navigator.appName == ‘Netscape’) {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0)
}
else {
if (navigator.platform == ‘Win32’ || navigator.platform == ‘Win16’) {
window.history.go(0)
}
}
}
}
else {
}

if (selected == ‘Other’) {
newCountry = “”;
while (newCountry == “”){
newCountry=prompt (“Please enter the name of your country.”, “”);
}
if (newCountry != null) {
inForm.country.options[(inForm.country.options.length-1)]=new Option(newCountry,newCountry,true,true);
inForm.country.options[inForm.country.options.length]=new Option(‘Other, not listed’,’Other’);
}
}
if(inForm.country.options[0].text == ‘Select country’) {
inForm.country.options[0]= null;
}
}
// End –>
</script>
<BODY>
<form name=”globe”>
<select name=”region” onChange=”populateCountry(document.globe,document.globe.region.options[document.globe.region.selectedIndex].value)”>
<option selected value=”>Select Region</option>
<option value=’asia’>Asia</option>
<option value=’africa’>Africa</option>
<option value=’australia’>Australia</option>
<option value=’europe’>Europe</option>
<option value=’middleeast’>Middle East</option>
<option value=’lamerica’>Latin America</option>
<option value=’namerica’>North America</option>
<option value=’samerica’>South America</option>
</select>
<select name=”country” onChange=”populateUSstate(document.globe,document.globe.country.options[document.globe.country.selectedIndex].text)”>
<option value=”><——————–</option>
</select>
</form>

MY FRANKENSTEIN SCRIPT
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=”JavaScript”>
<!–
var mesa = new Array(length=”3″ “(‘Please select resort of choice’,”,true,true)”,
“(‘Arizona Golf Resort’)”,
“(‘Sleep Inn, Mesa’)”);
var phoenix = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Gold Canyon’)”,
“(‘The Legacy Golf Resort’)”,
“(‘Point South Mountain Resort’)”,
“(‘Sheraton Wild Horse Pass Resort’)”,
“(‘The Wigwam Golf Resort’)”;
var scottsdale = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Hospitality Suite Resort’)”,
“(‘Orange Tree County’)”;
var tucson= new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Hilton Tucson El Conquistador’)”,
“(‘Omni Tucson Nation Golf Resort & Spa’)”,
“(‘Ramada Inn & Suites Foothills’)”,
“(‘Tubac Golf Resort’)”;
var palmsprings = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Comfort Inn Resort’)”,
“(‘La Quinta Resort & Club’)”,
“(‘Ramada Inn Resort’)”;
var sandiego = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Best Western Seven Seas Lodge’)”,
“(‘La Costa Resort & Spa’)”,
“(‘Rancho Bernardo Inn’)”,
“(‘Red Lion Hanalei Hotel’)”,
“(‘Temecula Creek Inn’)”;
var lasvegas = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Hyatt Regency Lake Las Vegas’)”;
var laughlin = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Flamingo Laughlin’)”;
var mesquite = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Casablanca Resort Casino’)”;
var reno = new Array(“(‘Please select resort of choice’,”,true,true)”,
“(‘Sands Regency Casino Hotel’)”;

function populateSelecthotel(inForm,selected) {
var selectedArray = eval(selected+”Array”);
while (selectedArray.length < inForm.selecthotel.options.length) {
inForm.selecthotel.options[(inForm.selecthotel.options.length -1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval(“inForm.selecthotel.options[k]=” + “new option” + selectedArray[i]);
}
if (inForm.resortform.options[0].value == ”) {
inForm.resortform.options[0]= null;
if ( naviator.appName == ‘Netscape’) {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == ‘Win32’ || navigator.platform == ‘Win16’) {
window.history.go(0);
}
}
}
}
if (inForm.selecthotel.options[0].text == ‘Please select resort of choice’) {
inForm.country.options[0]= null;
}

//–>
</script>
</head>

<body bgcolor=”#FFFFFF”>
<form name=”resortform” method=”post” action=””>
<select name=”selectcity” onChange=”populateSelecthotel(document.resortform,document.resortform.selectcity.options[document.resortform.selectcity.selectedArray].value)”>
<option selected value=”>Please select a city</option>
<option value=’mesa’>Mesa, Arizona</option>
<option value=’phoenix’>Phoenix, Arizona</option>
<option value=’scottsdale’>Scottsdale, Arizona</option>
<option value=’tucson’>Tucson, Arizona</option>
<option value=’palmsprings’>Palm Springs, California</option>
<option value=’sandiego’>San Diego, California</option>
<option value=’lasvegas’>Las Vegas, Nevada</option>
<option value=’laughlin’>Laughlin, Nevada</option>
<option value=’mesquite’>Mesquite, Nevada</option>
<option value=’reno’>Reno, Nevada</option>
</select>
<select name=”selecthotel”>
<option selected>——-</option>
</select>
</form>
</body>

Thanks, TL[COLOR=red]MY FRANKENSTEIN SCRIPT[/COLOR]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ExuroNov 18.2004 — I've attached a solution I wrote. The original function you were working off of made me kind of sick, so I re-wrote the whole thing. Your form is no longer inaccessible with JavaScript disabled, which is always a plus...

[upl-file uuid=08d75c3a-d499-4b90-9d2d-b358baaac94c size=5kB]example.txt[/upl-file]
×

Success!

Help @tlprice 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...