?
Solved

Making a survey using forms

Posted on 2003-03-10
26
Medium Priority
?
244 Views
Last Modified: 2013-12-25
I'm working on a survey for my site.  I have all the layout and forms created and each question has no more than 4 possible answers.  The survey is 7 pages and each input is a radio button with a number value.  I need to carry all the information as they select answers to the next page, and then at the end do a simple math calculation to come with a score.  I know I will need to use CGI and probably JavaScript, but I'm not sure where to begin.  Thanks for your help and let me know if you need additional information.
0
Comment
Question by:DrPcKen
[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
  • 11
  • 9
  • 6
26 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8118420
each page posts the values to your cgi script, which then shows the next page including the diven values as hidden variables.
This way the last page post all variables, including the ones from previous pages, and your cgi can perform the calculation.
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8121024
Ok, I made the forms (radio) and understand how the querystring works when i click submit.  But the form is 8 pages, how do I get the input to carry over when the form is started to when it finishes?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8121164
as I said, you script posts the given values as hidden INPUT variables in the next page, and so gets these values with the pages submit button.
Example page1:

<form action=your.cgi method=post>
  <input type=hidden name=page value=1>
  <input type=text   name=val1>
  <input type=submit>
</form>

then the CGI generates page 2:

<form action=your.cgi method=post>
  <input type=hidden name=page value=2>
  <input type=hidden name=val1 value="what ever">
  <input type=text   name=val2>
  <input type=submit>
</form>

and so on ..
0
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 
LVL 1

Author Comment

by:DrPcKen
ID: 8121196
So I change my form pages from .html to .cgi?  because right now that is what I put so when I click SUBMIT it takes you to the next page.

0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8121213
This is exactly what it says...

<form action=section2.html method=post>


then when you click SUBMIT, it puts the values of Section1.html into the querystring and takes you to the next page.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8121499
> .. <form action=section2.html method=post>
duh, does not make sence (on most web servers), except with special (in case loosy) configuration.
.html is a static file, usually, and does not process input (except section2.html is a program **and** the server accepts it as program).

you need:  <form action=your.cgi method=post>
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8121579
Ok I see your point.  So how would I make the your.cgi file?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8121682
choose you favorite programming language, then it goes as follows (convert to appropriate syntax):

  read posted data from STDIN;
  split result at & and store in a list;
  loop above list {
    split each list-value at = into name and value;
    store name and value;
  }
  increment value of accociated with name "page";
  if ($page lower-to your-last-page) {
    print "Content-type: html/text\n\n";
    print --whateverHTMLyouneed--;
    print "<form action=your.cgi method=post> ";
    print "<input type=hidden name=page value=$page>"
    loop over list of name-value-pairs {
      print "<input type=hidden name=$name value=$value>";
    }
    print --whateverothervaluesyoulike--;
    print "<input type=submit></form>";
  } else {
    process your data (see name-value pairs above);
  }
0
 
LVL 1

Accepted Solution

by:
chapatti earned 1200 total points
ID: 8122147
Hi DrPcKen,

You could carry the values forward with javascript also.

Change the form method to get and the value get carried forward in the url such as section2.html?firstq=2&secondq=3 etc.

Now on section2.html you parse the query string as follows:

function PageQuery(q){
     if(q.length > 1) this.q = q.substring(1, q.length);
     else this.q = null;
     this.keyValuePairs = new Array();
     if(q){
          for(var i=0; i < this.q.split("&").length; i++){
               this.keyValuePairs[i] = this.q.split("&")[i];
          }
     }
     this.getKeyValuePairs = function(){ return this.keyValuePairs; }
     this.getValue = function(s){
          for(var j=0; j < this.keyValuePairs.length; j++){
               if(this.keyValuePairs[j].split("=")[0] == s){
                    return this.keyValuePairs[j].split("=")[1];
               }
          }
          return -1;
     }
     this.getParameters = function(){
          var a = new Array(this.getLength());
          for(var j=0; j < this.keyValuePairs.length; j++){
               a[j] = this.keyValuePairs[j].split("=")[0];
          }
          return a;
     }
     this.getLength = function(){ return this.keyValuePairs.length; }    
}

Now you can access the Name/Value pairs:

     var NAME = page.getValue("name");

On the second page you add the values from the first page in hidden tags and do the get-thing again and parse the new set of values again, etc.

However, for the last form you will have to use a cgi script to forward the info.

TTFN,

chapatti
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8122536
Hmmm, I like the Javascript.  Ok, here is a snippet of code to help you guys see how my forms are working. This is question 1 of Section 1. Also, is there anything I'd have to add to that javascript above, or is that all I need?

<FORM ACTION="section2.html" METHOD="get" NAME="section1">
<BLOCKQUOTE><H2>1. How concerned are you about the safety and security of your company's critical information?</H2>
<TABLE WIDTH="25%" BORDER="0" CELLPADDING="0">
  <TR>
       <TD NOWRAP><p><INPUT TYPE="Radio" NAME="s1q1" Value="5"> Very concerned <I>(5 points)</i></P></TD>
  <TR>
     <TD NOWRAP><P><INPUT TYPE="Radio" NAME="s1q1" Value="3"> Somewhat Concerned <I>(3 points)</i></P></TD>
  <TR>
     <TD NOWRAP><P><INPUT TYPE="Radio" NAME="s1q1" Value="1"> Not very concerned <I>(1 point)</i></P></TD>
  <TR>
     <TD NOWRAP><P><INPUT TYPE="Radio" NAME="s1q1" Value="0"> Not concerned <I>(0 points)</i></P></TD>
</TABLE></BLOCKQUOTE>
0
 
LVL 1

Expert Comment

by:chapatti
ID: 8122678
That would be all you need to parse the querystring however you would have to fill in the hidden tags with javascript again so that you get the "page.getValue("name")" into the tag to get forwarded onto the next page.

Maybe you can even forward them within the form tag such as:

<FORM ACTION="section2.html?s0q1=4&s0q2=1&..." METHOD="get">

... in this case you would have to write the form tag line in javascript:

var test1 = page.getValue("s0q1");
var test2 = page.getValue("s0q2");

document.write('<FORM ACTION="section2.html?s0q1=' + test1 + '&s0q2=' + test2 + '&..." METHOD="get">');
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8122689
ahhhh
This is starting to make more sense!

Thanks alot!
I'll try some of this and let you guys know.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8128772
1. JavaScript does not solve the problem, at least if the browser does not support it, for any reason
2. I still do not see how you get the values with GET into your section2.html
  could you please explain?
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8129094
so instead of GET i should use POST?
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8129180
From my understanding, GET makes the querystring viewable in the URL, POST hides the values from the user.  
0
 
LVL 1

Expert Comment

by:chapatti
ID: 8129416
ahoffmann,
In regards to 1.
you are correct, it will not work if javascript is not enabled but this does not happen very often as it is turned on by default on the major browsers.

DrPcKen,
What is your target audience? Would they use text only browsers or turn off their javascript?

ahoffmann,
In regards to 2.
The "get" method will append the name / value pairs to the url thus making it possible for javascript to access.
Maybe it would work as well with the "post" method - I just haven't tried this yet.

0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8129447
I have no doubt that the target audience using this form will either be using IE or NETSCAPE (blah).  

The GET method stores the values in a visible querystring.  I'm not worried about this being displayed though.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8130981
hmm, didn't think of such a sophisticated function(), nice idea chapatti ;-)
0
 
LVL 1

Expert Comment

by:chapatti
ID: 8131026
Thanks ahoffmann!
0
 
LVL 1

Expert Comment

by:chapatti
ID: 8131443
Thanks ahoffmann!
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8142888
When I start the javascript (on section2 right?) i start the java script in the <HEAD> tag after the <SCRIPT="JavaScript"> Tag right?
0
 
LVL 1

Author Comment

by:DrPcKen
ID: 8142928
BTW, at the end of each section, it will have too add the value of all the questions together, divide by the total possible points (which is 50 in section1) and then multiply by 100.  

That math problem gives a value that needs to be carried over to the next page, and when all the values are gotten, it will ADD all the values from each section, divide by the number of sections completed and that equals your total score.

i'm still a bit confused about some of it :(
0
 
LVL 1

Expert Comment

by:chapatti
ID: 8153638

hey DrPcKen,

am currently a bit busy but will help you when i am done.

later,

chapatti
0
 
LVL 1

Expert Comment

by:chapatti
ID: 8153810

i am back now. just putting together a sample page for ya.

will let you know when done.

chapatti

0
 
LVL 1

Expert Comment

by:chapatti
ID: 8153954

me again,

here's the url to the test pages:
http://www.themediaco.com/testing/index.html

look at the source code to see how it's done.

what's left to do is, to check for empty radio boxes (if the user forgets to select an answer):
if(s1q1 != "-1"){
  // proceed
}else{
   // error message
}

cheers,

chapatti
0
 
LVL 1

Expert Comment

by:chapatti
ID: 8182077
Thanks for the points and the A!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

765 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