/    Sign up×
Community /Pin to ProfileBookmark

cannot got to page on onchege from dropdown

Hello:

I am having 2 dropdown list with states and forms and when i select the state it will populate corresponding forms of that state. When i select a form from the forms dropdown the event is firing but cannot display the url page

Following is the script i have written

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd“>
<html>
<head>
<title>Any Title</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<script type=”text/javascript”>

var forms= [];
forms[0] = [“A-4″,”A-4E”];
forms[1] = [“No Withholding Tax”];
forms[2] = [“A-4″,”WEC”,”A-4V”,”A-4M”,”WECI”];

function fillSelect(nValue,nList){

nList.options.length = 1;
var curr = forms[nValue];
for (each in curr)
{
var nOption = document.createElement(‘option’);
nOption.appendChild(document.createTextNode(curr[each]));
nOption.setAttribute(“value”,curr[each]);
nList.appendChild(nOption);
}
}

</script>
<style type=”text/css”>

body {background-color:#eae3c6;margin-top:60px}
form {width:330px;margin:auto}
fieldset {width:330px;background-color:#f0fff0;border:1px solid #87ceeb}
legend {font-family:times;font-size:14pt;color:#00008b;background-color:#87ceeb;padding-left:3px;padding-right:3px;margin-bottom:5px}
label {font-family:times;font-size:12pt;color:#00008B;padding:5px}
select {font-family:tahoma;font-size:10pt;width:125px;margin-left:27px}
.submitBtn {display:block;margin-left:auto;margin-right:auto;margin-top:5px;margin-bottom:5px}

</style>
</head>
<body>
<form method=”post” action=””>
<fieldset>
<select name=’states’ onchange=”fillSelect(this.value,this.form[‘forms’])”>
<option value=””>Select Your State</option>
<option value=”0″>Alabama</option>
<option value=”1″>Alaska</option>
<option value=”2″>Arizona</option>
</select>

<select name=’forms’

OnChange=”window.open(form.forms.options[form.forms.selectedIndex].value);
return false;”>
<option value=””>Select Form</option>

</select>

</fieldset>
</form>

</body>
</html>

Please Help

Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineJul 09.2010 — [CODE]OnChange="window.open(form.forms.options[form.forms.selectedIndex].value);[/CODE][/QUOTE]What is 'form' in this scope? [I]this.form[/I] maybe?

Assuming your select populates properly, within the scope of the form you should be able to use:[CODE]onchange = "window.open( forms.value )"[/CODE]
Copy linkTweet thisAlerts:
@tirnaJul 10.2010 — The way your code is structured atm, if I select form A-4 after selecting state Alabama the line

[CODE]<select name='forms'
OnChange="window.open(form.forms.options[form.forms.selectedIndex].value);
return false;">[/CODE]


then tries to open a file called 'A-4' which obviously does not exit.

Assuming the file names for your forms are the option value + .htm then maybe try

[CODE]
OnChange="window.open(form.forms.options[form.forms.selectedIndex].value[COLOR=red]+'.htm'[/COLOR]);
[/CODE]


It seems you simply need to change the url argument in the window.open() to evaluate to whatever the form file name is for the selected option.
×

Success!

Help @XFACTOR77 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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