Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2004, 02:02 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old July 17th, 2004, 05:31 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
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

Reply With Quote
  #3 (permalink)  
Old July 19th, 2004, 04:57 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old July 19th, 2004, 08:46 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
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

<><
Reply With Quote
  #5 (permalink)  
Old July 24th, 2004, 01:21 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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



Reply With Quote
  #6 (permalink)  
Old July 24th, 2004, 03:25 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
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

<><
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:00 AM.


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