How to compare two Value in JavaScipts:
1.Get the Value From Html Page using getElementById
2.Compare by Using parseInt For Interger Value and parseFloat For Float Value
3.compare two value as
var first=document.getElementById('first').value; var second=document.getElementById('second').value; if(parseInt(first)<parseInt(second)) alert('Second Value is Greater than first'); else if(parseInt(first)>parseInt(second)) alert('First Value is Greater than second'); else if(parseInt(first)==parseInt(second)) alert('First Value and second value is equal');
4.Include the code in Html Page For TextBox
First Value:<input type="text" value="0" onkeyup="compare();" name="first" id="first"> Second Value:<input type="text" value="0" onkeyup="compare();" name="second" id="second">
Popularity: 41% [?]
Related posts:

November 7th, 2008
admin
Posted in
Tags: 

How to compare not equal to in java script?
How can I compare String value?
Thank you very much… Instead of the above code..
I changed the code below…..
if(parseInt(first)< parseInt(second))
{
alert('Second Value is Greater than first');
textfirst.focus();
}
Im doing a similar thing but I want to have multiple comparisons but use the one javascript. at the moment the first set works perfectly but nothing after that. I could call the next set third and forth value etc but that would mean duplicating the javascript. is there a way around this?