Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Question Form

Posted on 2000-02-21
11
Medium Priority
?
216 Views
Last Modified: 2013-12-25
I want visitors of my website to fill in a form. Some questions of this form should not be answered when a certain answer has been given at a previous question. I want questions that should not be answered - because a certain answer was given earlier - to light up grey so that it is easy for the visitors to see that they do not have to answer these questions. Also I do not want it to be possible to enter text at such questions. Who can tell me how to programm this ? All answers are welcome, but i prefer the use of html or cgi. Thanks in advance
0
Comment
Question by:oostwijk
  • 4
  • 4
  • 3
11 Comments
 
LVL 18

Expert Comment

by:mgfranz
ID: 2543774
You can do this easily with a simple If..Then statement in either a VBScript or a Perl script.

Simply display a form based upon previous selections or answers can be done like this;

Say your form has a field called 'Glasses'

<form method=post action="new.asp">

What is your name? <input type="text" name="name"><br>
Do you wear glasses? <input type="text" name="glasses"><br>
<input type="submit" name="submit" value="Submit">
</form>

Now in new.asp;

<%
If Response.Form("glasses") = "Yes" 'you will need to play with the validation here, either 'true', 'false', 'NULL', NoData... etc
Then
%>
<form action=new2.asp>
I see you wear glasses, what kind? <input type="text" name="glasses"><br>
<input type="submit" name="submit" value="Submit">

</form>
<% Else %>
Since you don't wear glasses, what color are your eyes? <input type="text" name="color"><br>
<input type="submit" name="submit" value="Submit">
</form>


This is a very crude and simple way to do what you ask, let me know if you need more info.

Mark
0
 

Author Comment

by:oostwijk
ID: 2544197
What kind of programming language is that ? Can you give me the full code using CGI ?
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 2547153
This is done with VisualBasicScript, or VBScript.  It is the baseline code for ASP.  I haven't done any real programming in Perl for CGI in about two years... But I do know it can be easily done.  As I mentioned a simple If..Then loop will verify the existance of a true or false value.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:dmaryakh
ID: 2547251
Another approach will be using just client-side coding. Everytime the form is completed you scan it for right answers and append the number of the right answer to the cookie. You also can do that from your CGI form processing script. However when user loads next form in the browser you can have a JavaSctipt code that will analize the content of that cookie and based on the previous answers, will render new page. BTW at this point you might deside if you even want to show some of the textareas, and not just grey them out.
0
 
LVL 1

Expert Comment

by:dmaryakh
ID: 2547453
Another approach will be using just client-side coding. Everytime the form is completed you scan it for right answers and append the number of the right answer to the cookie. You also can do that from your CGI form processing script. However when user loads next form in the browser you can have a JavaSctipt code that will analize the content of that cookie and based on the previous answers, will render new page. BTW at this point you might deside if you even want to show some of the textareas, and not just grey them out.
0
 

Author Comment

by:oostwijk
ID: 2548354
Ok, is there anyone out there who can give me the code in CGI ???
0
 
LVL 1

Expert Comment

by:dmaryakh
ID: 2550903
This is whatmgfranz suggests, but implemented in CGI/Perl

This is the script to process the result of the initial questionary about glasses.


#!/usr/local/bin/perl
use CGI;
$query = new CGI;

print $query->header;
print "<HTML>\n<HEAD>\n<TITLE>Second Questionare</TITLE>\n</HEAD>\n";
print "<BODY>\n";
print "<FORM METHOD=post ACTION=\"new.cgi\">\n";

if($query->param('glasses') eq 'Yes'){
   print "I see you wear glasses, what kind? <input type='text' name='glasses'><br>"
} else {
   print "Since you don't wear glasses, what color are your eyes? <input type='text' name='color'><br>"
}


print '<input type="submit" name="submit" value="Submit">'

0
 

Author Comment

by:oostwijk
ID: 2552425
How can I modify these lines you gave me so that -after the user has given a certain answer to a previous question- certain following questions on the SAME page (!!) will be disabled? With disabled I mean that it will not be possible to give an answer to these questions. Preferably it must be noticable for the user that it is no longer necessary to answer these questions. Thanks....
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 2552546
<form method=post action="new.cgi">

What is your name? <input type="text" name="name"><br>
Do you wear glasses? <input type="text" name="glasses"><br>
<input type="submit" name="submit" value="Submit">
</form>

The values are then passed to the .cgi above, then the outputs are evaluated.

You can have whatever you want under the true or false fields.
0
 
LVL 1

Expert Comment

by:dmaryakh
ID: 2554847
It looks like I misunderstood your question slightly. It appears that you want to enable/disable question on the form without submitting it. You can do that with client-side scripting.

Once the information in your form element changes, you have to analize it and based on the analisys turn-off some of your form components.




<HTML>
<SCRIPT>
     var WEARS_GLASSES=true;

     function to_blur_or_not_to_blur(){
          if (!WEARS_GLASSES){
               MYFORM.GLASSESTYPE.blur();
          }
     }

     function processGlasses(){
          if (MYFORM.GLASSES.checked) {
               WEARS_GLASSES=true;
               MYFORM.GLASSESTYPE.value="";
          } else {
               WEARS_GLASSES=false;
               MYFORM.GLASSESTYPE.value="skip this question";
          }
     }

</SCRIPT>
<BODY>
     <FORM NAME=MYFORM>
          Check this box if you wear glasses:
          <INPUT TYPE=CHECKBOX NAME=GLASSES onClick="processGlasses()" CHECKED>
          <BR>
          What type of glasses do you wear?:
          <INPUT TYPE=TEXT NAME=GLASSESTYPE onFocus="to_blur_or_not_to_blur()">
     </FORM>
</BODY>
</HTML>
0
 
LVL 18

Accepted Solution

by:
mgfranz earned 150 total points
ID: 2606297
Did yo get this fixed?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

926 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