Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question Form

Posted on 2000-02-21
11
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
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:
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

722 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