/    Sign up×
Community /Pin to ProfileBookmark

Serving up different pages based on form selection

I have a form on my website with two questions. Each question has five possible answers that use radio buttons. The options for this form look like this (both questions are excerpted for your viewing pleasure):

[code=html]<li class=”narrative”>How would you best describe the nature of your business?<br>
<input type=”radio” name=”question1″ value=”a”>a. Business to business<br>

<input type=”radio” name=”question1″ value=”b”>b. E-commerce<br>
<input type=”radio” name=”question1″ value=”c”>c. Retail<br>
<br><br>
<li class=”narrative”>What is blah blah?<br>
<input type=”radio” name=”question2″ value=”a”>a. Less than $500<br>
<input type=”radio” name=”question2″ value=”b”>b. $500 – $10,000<br>
[/code]

When someone submits this form, if they have selected option B in the first question, I want to take them to a different page than the primary form submit page. If they have selected C, I want to take them to yet another page. OR then if they select option A in the second question, yet another. If they select any other choices for either question, the form should just submit as normal. How can this be accomplished?

I am not sure if this can be done in Javascript or not, since I can’t find anything on the Internet about it. Thanks for taking the time to check this out.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@blistexauthorJun 29.2005 — Also: I am reasonably tech-savvy and can put together a very basic Javascript function, so level of complication should not be too much of a problem so long as I can find at least a direction to go in.
Copy linkTweet thisAlerts:
@blistexauthorJun 30.2005 — Okay, if I define a variable array that uses the values from the radio button questions, is there any JS function I could use in an if...else clause? Like location.href perhaps?
Copy linkTweet thisAlerts:
@Mr_JJun 30.2005 — Try the following example to see if it is on the right lines


[code=php]<script type="text/javascript">
<!--
function test(){

direct="default.htm"

if(document.myform.question1[1].checked){
direct="Page1.htm"
}

if(document.myform.question1[2].checked){
direct="Page2.htm"
}

if(document.myform.question1[2].checked&&document.myform.question2[0].checked){
direct="Page3.htm"
}

alert(direct)

//location.href=direct
}

//-->
</script>

<form name="myform">
<li class="narrative">How would you best describe the nature of your business?<br>
<input type="radio" name="question1" value="a">a. Business to business<br>

<input type="radio" name="question1" value="b">b. E-commerce<br>
<input type="radio" name="question1" value="c">c. Retail<br>
<br><br>
<li class="narrative">What is blah blah?<br>
<input type="radio" name="question2" value="a">a. Less than $500<br>
<input type="radio" name="question2" value="b">b. $500 - $10,000<br>

<input type="button" value="Button" onclick="test()">
</form>[/code]
Copy linkTweet thisAlerts:
@blistexauthorJun 30.2005 — That is great, thanks - the "checked" element is a lot simpler than the functions I was trying to create. The only problem is that even with assigning the URLs to a variable, the location.href comman isn't redirecting the browser. I used the alert function to check, and it is recording the right URLs, but it doesn't seem to recognize location.href as a valid command (I tried it with and without the slashes). Is there any reason this would happen?
Copy linkTweet thisAlerts:
@Mr_JJun 30.2005 — Did you put in the correct file name, I just noticed I capitalised the p in page

Try the examples in the attached zip file

[upl-file uuid=4e52d8b2-3bb3-4c31-80f5-82295ae665a2 size=1kB]redirect.zip[/upl-file]
Copy linkTweet thisAlerts:
@blistexauthorJul 01.2005 — Yes, I replaced all of the pages with the hard-coded URLs for the actual pages (i.e. not relative links). Does that make a difference?
Copy linkTweet thisAlerts:
@Mr_JJul 01.2005 — If you use absolute paths the script will only work online.

Did the example files in the zip work?
×

Success!

Help @blistex 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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