Jump to content

Javascript if (x >y) { // do somthing } not working


ScotDiddle

Recommended Posts

Hi Folks,

 

I have a simple js function which is called during onBlur of an input field.

 

if (7 > 9) { } is returning true.  ...but not always...  :( 

 

Can anyone see anything wrong with my code ?

 

See the last "if" statement...

 


function checkInventory(quan,curval,thisid,closeout) {

// alert(closeout);

closeoutBoolean = closeout;

if (curval < quan || curval == quan) {

	thisid++ ;

	var quanFeild = document.getElementById(thisid);

	quanFeild.value = quan;

}

if (curval == '0' || curval == '') {

	var quanFeild = document.getElementById(thisid);

	quanFeild.value = '';

}

alert('curval ' + curval);
alert('quan ' + quan);


if (curval > quan) {

	$(document).ready(function(){

		var url = "<?php echo $toodles; ?>backorder.php?height=375&width=375&modal=true&curval=" + curval + "&quan=" + quan + "&quanid=" + thisid + "&closeout=" + closeoutBoolean;

		tb_show("",url,"");

	});
	}
}



 

Thanks, Scot L. Diddle, Richmond VA

Link to comment
Share on other sites

Salutations,

 

    Turns out that passing '7' is not the same as passing 7.

 

    My onBlur call to the JS Function was passing 7, and this resulted in a JS error, so I change it to '7'.

 

    To fix the error, I had to turn the text I was passing in to an INT, via:

 


quan = quan * 1;
curval = curval * 1;

 

Silly Me.

 

Thanks for looking.

 

Scot L. Diddle

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.