• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 943
  • Last Modified:

jquery single declaration; whole usage on site

I've got script (JQUERY .js) and it only works on the 1st declaration (in input); then it doesn't works on the second input. What to do?
JQUERY .js
$(document).ready(function(){$("#quantity").keypress(function(e){if(e.which!=8&&e.which!=0&&(e.which<48||e.which>57))return false})});
 
 
HTML
<input type=text name=price0 id=quantity class=align_right size=10 value='<% $_POST[price0] %>' maxlength=10 />
						  		.<input type=text name=price0_2 id=quantity size=1 value='<% if $_POST[price0] <> '' AND $_POST[price0_2] == '' %>00<% else %>00<% $_POST[price0_2] %><% /if %>' maxlength=2 /><% $currency %>&nbsp;

Open in new window

0
AndyPSV
Asked:
AndyPSV
  • 3
  • 3
1 Solution
 
brandonvmooreCommented:
I'm just learning jquery so I don't know how much help I'll be, but at first glance I'm a little confused by your keypress event.  It doesn't 'do' anything, it just returns a value of false under the right considitions.  Does returning a false value cancel the event or something?
0
 
AndyPSVAuthor Commented:
It just does what it suposse to do - allows only digits to be typed in the box (in the first input)
0
 
brandonvmooreCommented:
if (   e.which!=8 &&   //not backspace
       e.which!=0 &&   //not null
      (e.which < 48 || e.which > 57))  //less than '0' OR greater than '9'
      return false

By this logic you are exluding digits.  It should either say:

(e.which >= 48 || e.which <= 57)

or you could write it like:

!(e.which < 48 || e.which > 57)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
AndyPSVAuthor Commented:
it ain't work
0
 
brandonvmooreCommented:
Sorry, I didn't mean to infer that would fix the problem that you were asking about.  I just meant that if your goal is to only allow numbers to be typed in then even if you fixed that problem it still wouldn't work until you corrected the part that I was pointing out.

Have you tried doing this without using jquery?  You might see if you can implement it w/o using jquery just as a test to see whether the issue is related to jquery or not.
0
 
AndyPSVAuthor Commented:

$(document).ready(function(){$('#phone_cc').keypress(function(e){if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)){return false;}});});

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now