Solved

Question Form

Posted on 2000-02-21
11
183 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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 50 total points
ID: 2606297
Did yo get this fixed?
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rearranging, beautifying pure CSS read more script 5 55
Form Processing in PHP 11 41
Wrapper for APPs 9 76
paypal ipn url 5 56
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Read about why website design really matters in today's demanding market.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

776 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