Posts Tagged ‘compare’

Javascript compare two numbers

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">

Demo Link

Popularity: 51% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars