Solved

Question Form

Posted on 2000-02-21
11
166 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
gzip in express of nodejs 12 67
Does it make sense migrate a website to MIcrosoft Azure 4 26
Menu Inconsistent 3 19
WEB Farm 6 23
Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
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…
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.

708 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

14 Experts available now in Live!

Get 1:1 Help Now