Link to home
Start Free TrialLog in
Avatar of AndyPSV
AndyPSVFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of brandonvmoore
brandonvmoore

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?
Avatar of AndyPSV

ASKER

It just does what it suposse to do - allows only digits to be typed in the box (in the first input)
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)
Avatar of AndyPSV

ASKER

it ain't work
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.
ASKER CERTIFIED SOLUTION
Avatar of AndyPSV
AndyPSV
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial