Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-14-2011, 08:22 PM   PM User | #1
Jamesc
New to the CF scene

 
Join Date: Dec 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Jamesc is an unknown quantity at this point
Guessing Game Help.

What I'm trying to achieve is it initialises a number between 1-2000 randomly.
When the submit button is clicked it simply returns if the number that is in putted is higher or lower than the randomly initialised number.
External JavaScript:

Html
Code:
<html>
<head>
<script type="text/javascript" src="jsscri.js"></script>
</head>
<body onload="initialisation ()">

<form name="exampleform">
 <h3>
Number: <input name="number" type="text" 
            onchange='checkNumber( this.value );'>
</h3>
 <p>
	<input name="submit" type="button" value="Guess"
	onclick= 'checkValue()';/>  
 </p>
 

</body>
</html>
If you load this onto a webpage you'll see what i'm trying to do. I tried deleting the rest of the code to keep the size of the code down.

Last edited by Jamesc; 12-14-2011 at 09:34 PM..
Jamesc is offline   Reply With Quote
Old 12-14-2011, 08:34 PM   PM User | #2
mvmacd
New Coder

 
Join Date: Nov 2011
Location: New England
Posts: 62
Thanks: 0
Thanked 10 Times in 10 Posts
mvmacd is an unknown quantity at this point
"checkNumber" is not a function. Did you leave some code out?

Also, you misspelled initialization as "initialisation" in the onload.
__________________
For programming information, visit irnsystems.com
Also check out Points2Survey and earn items.

Last edited by mvmacd; 12-14-2011 at 08:36 PM..
mvmacd is offline   Reply With Quote
Old 12-14-2011, 08:41 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,188
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Also, the checkValue( ) function requires a single argument passed to it.

When invoked from the "Guess" button, no value is supplied.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-14-2011, 08:42 PM   PM User | #4
Jamesc
New to the CF scene

 
Join Date: Dec 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Jamesc is an unknown quantity at this point
Sorry. I changed the spelling. Heres the check function. It checks the in-putted text and alerts the user if the number they put is outside the range of 0-2000.

Code:
function checkNumber(num) 
{
   
   if ( isNaN(num) || num < 0 || num > 2000) {
      alert( num + " Number has to be between 0 - 2000");
   }
}
Quote:
Also, the checkValue( ) function requires a single argument passed to it.
Code:
<p>
	<input name="submit" type="button" value="Guess"
	onclick= 'checkValue(num)';/>  
 </p>
Is this right? I'm not sure if it looks at the values in the input box then checks.

Last edited by Jamesc; 12-14-2011 at 08:52 PM..
Jamesc is offline   Reply With Quote
Old 12-14-2011, 09:13 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,188
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
How could num possibly be right?

Look here:
Code:
    <input name="number" ...
So:
Code:
	<input name="submit" type="button" value="Guess"
	    onclick="checkValue(this.form.number.value)" />
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Jamesc (12-14-2011)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:28 AM.


Advertisement
Log in to turn off these ads.