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

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 02-24-2011, 12:59 PM   PM User | #1
kreut
New Coder

 
Join Date: Feb 2011
Location: Bellingham, WA
Posts: 31
Thanks: 11
Thanked 0 Times in 0 Posts
kreut is an unknown quantity at this point
Using jquery to check textboxes

Hello,

I'd like to write some jquery code which will check to see if the contents of a textbox are equal to some value after the user leaves the textbox. they should get a message saying Correct or Incorrect . As an example:

Code:
 <td>-2</td>
    <td><input name="ans1" type="text" size="3" maxlength="3" /></td>
  </tr>  <  The correct answer here would be 5 >
  <tr>
    <td>-1</td>
    <td><input name="ans1" type="text" size="3" maxlength="3" /></td> < The correct answer here would be 4>
And, I don't wish to abuse the forum, but as I'm learning javascript and jquery, I'd like to see solutions to both (I learn by example), so I'm posting the same question in the main JavaScript programming forum with a request for a Javascript solution; I hope that this isn't bad form!

Thank you.....
kreut is offline   Reply With Quote
Old 02-25-2011, 02:57 PM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Quote:
Originally Posted by kreut View Post
I'd like to write some jquery code which will check to see if the contents of a textbox are equal to some value after the user leaves the textbox. they should get a message saying Correct or Incorrect
Code:
$('input[type=text]').blur(function(){
	$('<span>').text(($(this).val()=='the_right_answer') ? 'Correct' : 'Wrongamundo').insertAfter($(this));
});
Quote:
Originally Posted by kreut View Post
And, I don't wish to abuse the forum, but as I'm learning javascript and jquery, I'd like to see solutions to both (I learn by example), so I'm posting the same question in the main JavaScript programming forum with a request for a Javascript solution; I hope that this isn't bad form!.
Cross-posting is generally frowned upon. But as a word of advice - don't get caught thinking you can learn jQuery instead of javascript. jQuery is a javascript framework; it's great at reducing the amount of code you have to write, but over-reliance on it will get you into all sorts of pain.
Spudhead is offline   Reply With Quote
Users who have thanked Spudhead for this post:
kreut (02-25-2011)
Old 02-25-2011, 05:24 PM   PM User | #3
kreut
New Coder

 
Join Date: Feb 2011
Location: Bellingham, WA
Posts: 31
Thanks: 11
Thanked 0 Times in 0 Posts
kreut is an unknown quantity at this point
Thank you for both your solution (it actually makes sense!) and your suggestion about understanding javascript (I got the same advice in the other forum).

In addition, I won't do any cross postings in the future.
kreut is offline   Reply With Quote
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 09:17 PM.


Advertisement
Log in to turn off these ads.