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

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

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.