Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2004, 02:02 AM
Authorized User
 
Join Date: Jul 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Button Help

Hi

I'm new to javascript.I'm trying to do a basic quiz project werein if a question is displayed it should have yes or no buttons.If any one of the button is clicked in the next line it should display next question again with yes or no button.This should be repeated for atleast 10 question. At the end of 10 questions it should generate a summary in text box.can anyone help me. Thank you in advance.

Pradeep

 
Old July 17th, 2004, 05:31 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Pradeep,

Are you trying to dynamically make the questions appear on the page? Not quite sure what you're trying to achieve....

interrupt

 
Old July 19th, 2004, 04:57 AM
Authorized User
 
Join Date: Jul 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The questions should appear dynamically on the webpage as soon as I press Yes or No button. This is like Question & Answers

 
Old July 19th, 2004, 08:46 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

<div id='q'>

</div>
<script type='text/javascript'>
var buttons_1 = '<br/><br/><input type="button" onclick="yes(';
var buttons_2 = ')" value="yes"/><input type="button" onclick="no(";
var buttons_3 = ')" value="no"/>';
var answers = new array();
var questions = new array();

var limit = 3;

questions[0] = "true or false?";
questions[1] = "true or false?";
questions[2] = "true or false?";

document.getElementById('q').innerHTML = questions[0];
document.getElementById('q').innerHTML += buttons_1 + '0' + buttons_2 + '0' + buttons_3;

function yes(num)
{
 answers[num] = 'yes';
 nextQuestion(num);
}
function no(num)
{
 answers[num] = 'no';
 nextQuestion(num);
}
function nextQuestion(num)
{
 num++;
 if(num==limit)displayResults;
 else {
 document.getElementById('q').innerHTML = questions[num+1];
 document.getElementById('q').innerHTML += buttons_1 + (num.toString());
 document.getElementById('q').innerHTML += buttons_2 + (num.toString());
 document.getElementById('q').innerHTML += buttons_3;
 }
}
function displayResults()
{
 for(var i=0; i < limit; i++)
 {
  document.getElementById('q').innerHTML = 'Question: ';
  document.getElementById('q').innerHTML += questions[i];
  document.getElementById('q').innerHTML += '<br/>Your answer: ';
  document.getElementById('q').innerHTML += answers[i];
  document.getElementById('q').innerHTML += "<br/><br/>";
 }
}
</script>

This script is designed to ask three questions..... just change the value of 'limit' to add more.

Not tested, no guarantees :-)

Also, IE only.

HTH,

Snib

<><
 
Old July 24th, 2004, 01:21 PM
Authorized User
 
Join Date: Jul 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I tried with this code but I get only blank webpage.
Let me try to give an example behind this project.

This webpage uses frames.
On left pane of IE I have a button by name ************(Gender).When I click on ************ button I right pane I should get a question ARE YOU MALE OR FEMALE with 2 buttons MALE & FEMALE. If I click on MALE button I should get somemore questions with relevant buttons.At the end of questions it should generate a summary.

I hope it is clear now.
Thanks in Advance.

Pradeep



 
Old July 24th, 2004, 03:25 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Put this attribute in the body so that it looks like this:

<body onload="nextQuestion(-1)">

HTH,

Snib

<><





Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
button mustang Visual Basic 2005 Basics 3 March 13th, 2006 09:12 AM
how to use 'Enter' button to trigger a button, thx raybristol ASP.NET 1.0 and 1.1 Basics 1 December 16th, 2005 06:56 AM
Button within a button Dwizz VB.NET 2002/2003 Basics 7 June 1st, 2005 08:23 AM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.