Solved

Question Form

Posted on 2000-02-21
11
177 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Read about why website design really matters in today's demanding market.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

914 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now