Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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 5th, 2004, 07:51 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Textarea, Variables and Such Like

Hi People,

Heres my prob:

I have a textarea. the user must input two of three answers, but one of the answers must be included to score a point. So it must work like this:

Answer Score
A 0 without B, 1 with B
B 1 with A or B (0 without A or B)
C 0 without B, 1 with B

So you need B+A or B+C, nothing else will give you a point.
Heeeeeeeeeeelp!!!!!!

interrupt

__________________
\'sync\' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
 
Old July 5th, 2004, 09:00 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Why don't you use checkboxes? I don't see how this can be done with a textarea.

Check two out of three:<br>
<input type=checkbox id=cb1> A<br>
<input type=checkbox id=cb2> B<br>
<input type=checkbox id=cb3> C<br>
<input type=button value="check" onclick=alert(checkAnswers())>

<script type=text/javascript language=javascript>
var cb1=document.getElementById('cb1');
var cb2=document.getElementById('cb2');
var cb3=document.getElementById('cb3');
function checkAnswers()
{
 if(cb1.checked=true && cb2.checked=true)return "GOOD";
 else if(cb2.checked=true && cb3.checked=true)return "GOOD";
 else return "BAD";
}

</script>

HTH,

Snib

<><
 
Old July 5th, 2004, 09:27 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks snib thats great, but I am getting a syntax error, don't mean to moan, but I can't find it!




Quote:
quote:Originally posted by Snib
 Why don't you use checkboxes? I don't see how this can be done with a textarea.

Check two out of three:<br>
<input type=checkbox id=cb1> A<br>
<input type=checkbox id=cb2> B<br>
<input type=checkbox id=cb3> C<br>
<input type=button value="check" onclick=alert(checkAnswers())>

<script type=text/javascript language=javascript>
var cb1=document.getElementById('cb1');
var cb2=document.getElementById('cb2');
var cb3=document.getElementById('cb3');
function checkAnswers()
{
if(cb1.checked=true && cb2.checked=true)return "GOOD";
else if(cb2.checked=true && cb3.checked=true)return "GOOD";
else return "BAD";
}

</script>

HTH,

Snib

<><
 
Old July 5th, 2004, 09:41 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Interrupt,

checked=true should be checked == true

Cheers,

Chris

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

Sorry..... should be:

Check two out of three:<br>
<input type=checkbox id=cb1> A<br>
<input type=checkbox id=cb2> B<br>
<input type=checkbox id=cb3> C<br>
<input type=button value="check" onclick=alert(checkAnswers())>

<script type=text/javascript language=javascript>
var cb1=document.getElementById('cb1');
var cb2=document.getElementById('cb2');
var cb3=document.getElementById('cb3');
function checkAnswers()
{
 if(cb1.checked==true && cb2.checked==true)return "GOOD";
 else if(cb2.checked==true && cb3.checked==true)return "GOOD";
 else return "BAD";
}

</script>

HTH,

Snib

<><
 
Old July 5th, 2004, 09:51 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thats just the thing I need Snib. Thanks for that.

interrupt






Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab function + <textarea></textarea> Adam H-W HTML Code Clinic 0 April 24th, 2007 10:36 AM
Apostrophe in a textarea myself Classic ASP Professional 9 June 8th, 2006 07:32 AM
display vbCrLf's from textarea to textarea mat41 Classic ASP Basics 8 June 10th, 2004 12:19 AM
Textarea problem chiraagb HTML Code Clinic 11 June 9th, 2004 11:25 AM
TextArea microchip Classic ASP Databases 2 March 17th, 2004 11:19 AM





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