Results 1 to 2 of 2

Creating questions and answers forms for your web pages

This is a discussion on Creating questions and answers forms for your web pages within the Web Design forums, part of the Web Designing & Development category; Following JavaScript code can help you to easily create Q and A forms for your web pages without using CGI ...

  1. #1
    Senior Member Array akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    500

    Default Creating questions and answers forms for your web pages

    Following JavaScript code can help you to easily create Q and A forms for your web pages without using CGI scripts. You can also make it redirect the visitor to another web page depending on the answer.

    Code:
    <SCRIPT language="JavaScript"
            type="text/javascript">
    <!--
    //
    // Documentation:
    //   http://chami.com/tips/javascript/
    //
    function checkAnswer(quizForm,
                         theAnswer,
                         urlRight,
                         urlWrong)
    {
      var s = "?";
    
      // go through the "current choices"
      // to find the selected choice.
      // radio boxes pointing to choices
      // must be named "cc"
      // change if necessary
      //
      var i = 0;
      for(;i<quizForm.elements.length;i++)
      {
        if(("cc" ==
            quizForm.elements[i].name) &&
           (quizForm.elements[i].checked))
        {
          s = quizForm.elements[i].value;
        }
      }
    
      // no choice was selected
      //
      if("?" == s)
      {
        alert("Please make a selection.");
        return false;
      }
    
      // check if we have the correct
      // choice selected
      //
      if(s == theAnswer)
      {
        alert("'"+s+"' is correct!");
        if(urlRight)
        {
        document.location.href = urlRight;
        }
      }
      else
      {
        alert("'"+s+"' is incorrect.");
        if( urlWrong )
        {
        document.location.href = urlWrong;
        }
      }
    
      // return "false" to indicate not to
      // submit the form.
      // change this to "true" if the form
      // "action" is valid,
      // i.e. points to a valid CGI script
      //
      return false;
    }
    //-->
    </SCRIPT>
    following HTML tags to create your quiz form
    Code:
    <FORM method="POST"
          onSubmit="return checkAnswer(this,'B');"
    >
    
    <INPUT TYPE="RADIO" VALUE="A" NAME="cc">
    A. Another name for Java<BR>
    
    <INPUT TYPE="RADIO" VALUE="B" NAME="cc">
    B. A scripting language mostly for the web<BR>
    
    <INPUT TYPE="RADIO" VALUE="C" NAME="cc">
    C. When you use Java without compiling<BR>
    
    <INPUT TYPE="SUBMIT" VALUE="Submit Answer">
    
    </FORM>

  2. #2
    Senior Member Array msn90's Avatar
    Join Date
    May 2009
    Location
    india
    Posts
    146

    Thumbs up Re: Creating questions and answers forms for your web pages

    Thanks akash for sharing this. i'm a web designers. i think it is very helpful for me.

    Thanks very very much.



Similar Threads

  1. Interview questions and answers for SEO
    By bradchawla in forum Career
    Replies: 17
    Last Post: 01-12-2012, 08:26 PM
  2. Replies: 7
    Last Post: 08-26-2011, 01:54 AM
  3. Replies: 7
    Last Post: 09-14-2009, 08:28 AM
  4. Replies: 1
    Last Post: 02-05-2008, 12:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO Forum | Web Hosting Forum | Websites For Sale |