[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Online Questionnaire, mult questions, no sends to one page, yes sends to another

Posted on 2005-05-09
10
Medium Priority
?
204 Views
Last Modified: 2010-04-09
Hi there,

I've been asked to create a questionnaire for our site which has a number of questions with radio buttons. In section one, if any one of the 7 questions is answered with a "no", the user is sent to a specific link. If all questions are yes, the user is sent to the next section. I cannot find any scripts anywhere that would perform this action. I found one that would work if the user was to see only one question at a time (like a survey) but I'd really like to reduce the number of web pages they have to go through.

Example - section 1
                    Yes   No
Heart Attack    0      0
Broken Leg      0      X  < a no here sends them to page 1 .. otherwise page 2
Insomnia         0      0
0
Comment
Question by:boukaka
  • 6
  • 3
10 Comments
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 13964053
do you use server-side scripting like PHP JSP ASP, GGI, Coldfusion?
if so, you can always submit to the same page (page 1), then have your server side check the values and redirect to page 2 if there is a "no".
otherwise, you can use javascript to change your form's "action".
0
 

Author Comment

by:boukaka
ID: 13964072
Actually, I had thought of ASP after I posted here in the HTML section and re-posted the question over there. One member has a script which would validate a question and I've sent off a clarifying question asking if the same script would work if I added additional questions (i.e. would they all be validated at the same time)

My problem isn't really validating a single question, it's having multiple questions validated at the end of the script and from there redirecting the user.
0
 

Author Comment

by:boukaka
ID: 13964211
I've found the answer in the asp section - thank you for your help.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:boukaka
ID: 13964232
Please Close
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13964352
here is my answer anyway, it saves server side work

This is easily done with client side script. How are the question organised, are they all the sections in a single form? And is a a no  for one or more in the first 7 questions that sends them to the another page, else proceed to next page. eg for 3 in 1st question group

<script language="JavaScript">
function checkNo(theForm){
 numCheck=2*3
 els=theForm.elements
 for (i=1;i<numCheck;i=i+2)
  if (els[i].type=='radio'&& els[i].checked){
    theForm.action="http://yahoo.com"
    break
  }
 return true
}
</script>

<form action="http://google.com" onsubmit="checkNo(this)">
  <p>yes&nbsp;&nbsp;no</p>
  <p>Section 1</p>
  <p><input type="radio" name="qa1" checked><input type="radio" name="qa1">Q1</p>
  <p><input type="radio" name="qa2" checked><input type="radio" name="qa2">Q2</p>
  <p><input type="radio" name="qa3" checked><input type="radio" name="qa3">Q3</p>
  <p>Section 2</p>
  <p><input type="radio" name="qb1" checked><input type="radio" name="qb1">Q1</p>
  <p><input type="radio" name="qb2" checked><input type="radio" name="qb2">Q2</p>
  <p><input type="radio" name="qb3" checked><input type="radio" name="qb3">Q3</p>
  <p><input type="submit"> </p>
</form>
0
 

Author Comment

by:boukaka
ID: 13967491
Wow, Gwyn, this works better than the other answer that I accepted, it gives me all questions on one page which was really what I was going for! Would it be difficult to take this and have the form remember the answers and send them to our server for storage via something like.. xml or whatever? We are working with SQL Server 2000.
I'm upping the point value for this one. Thanks!
0
 

Author Comment

by:boukaka
ID: 13967929
Also, I have 7 questions not 6. Can I assume that if I change the J-script to say
<script language="JavaScript">
function checkNo(theForm){
 numCheck=7
 els=theForm.elements
 for (i=1;i<numCheck;i=i+2)
  if (els[i].type=='radio'&& els[i].checked){
    theForm.action="http://yahoo.com"
    break

.... .and remove the <p>section 2</p> that this would work with 7 questions?
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 1200 total points
ID: 13968659
"Also, I have 7 questions not 6"

use 2*numberToCheck,  so for 7 questions use  numCheck=2*7=14  (this is because there are 2 radio buttons per questions).
You can add and subtract both section names and questions at will. If the questions are in a form then the answers will be sent to the server when submitted.  
0
 

Author Comment

by:boukaka
ID: 13968717
Ah, I get it, so if I embed this script with my adjustments in to the body of the form, I should be good to go, correct? (maybe I'll get the programmers to do that) I feel so useless when it comes to this stuff.

Thank you very much for your help.
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13968975

>>Ah, I get it, so if I embed this script with my adjustments in to the body of the form<<

yes, but no need for the script to be in the form itsself it can go in the head

thx for the points :-)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question