1

I have two textboxes that will be used to search for the amount of Weapon, therefore Weapon Range Amount.

Either of the two is blank is ok, but the 2nd textbox shouldnt be greater than the value of the 1st textbox.

I'm torn between the tests made by keyup and change

the code's behavior is

1)Input 11(higher number) on 1st textbox 2)hit Tab 3)Input 2(lower number) on the 2nd 4)alert fires up

11>2 right? but the it still got inside the

if (weaponLess < weaponMore)

fyi

var weaponLess=$("#weaponAmtSuuji1").val();
var weaponMore=$("#weaponAmtSuuji2").val();

seems it compared the value of the 2nd textbox before it got an input

I have a hidden textbox which I showed on the code, and it should capture both of the input and should check if each of the two has an input or none

then join the inputs in a pattern like "WeaponAmount < "+txtBox1+" AND WeaponAmount > "+txtBox2"

html

Search Weapon Amount Range
<br>
<label>Weapon Amount Less</label>&nbsp
<input type="text" id="weaponAmtSuuji1"/>&nbsp<span id="weaponAmtErrmsg1"></span>&nbsp
<br>
<label>Weapon Amount More</label>&nbsp
<input type="text" id="weaponAmtSuuji2"/>&nbsp<span id="weaponAmtErrmsg2"></span>
<br>
<input type="text" name="WeaponAmount" id="weaponAmtFld">

jquery

http://jsfiddle.net/yuuto/75V8S/

you may noticed I put

/*$('#weaponAmtFld').val(function(index, val) {
 if (val.indexOf("AND")>0)...

on comment, if removed it, the script doesnt seem to perform even the

if (weaponLess < weaponMore) {

parts

really need help

3
  • 11>2 right? -> not necessarily (on a string compare, 11 is lower than 2 because of the alphanumeric order) Commented May 19, 2014 at 11:39
  • before I forget, I restricted the textboxes to accept only numbers Commented May 19, 2014 at 11:52
  • event if they accept numbers, the type must be number (try typeof on your variables) Commented May 19, 2014 at 11:54

1 Answer 1

1

String compare rules :) (see my comment)

http://jsfiddle.net/75V8S/2/

if (parseInt(weaponLess) < parseInt(weaponMore)) {
Sign up to request clarification or add additional context in comments.

9 Comments

have you tried inputting say 11 for 1st field and 2 for the 2nd? the script fires the alert even if the inputs are valid
Hell yeah, there is another bug here :/
my next guess is that you use the same variable for all your events, I try to fix that...
here we are: jsfiddle.net/75V8S/3 in fact you had another string comparison :p This may be nicely factorised, you know?
Thanks for fixing, now before copying values to weaponAmtFld, I would like to make my code $('#weaponAmtFld').val(function(index, val) { if (val.indexOf("AND")>0) { val=val.replace(/.+?AND/,"BetAmount < "+event.target.value+ " AND"); return val; } else return "BetAmount < "+event.target.value+" AND"; } to work, coz it doesnt work inside the else branch
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.