Reputation: 1733
Looking for the best approach to perform a javascript notification pop-up if amount in field A is edited to a smaller amount that what is found in field B?
We aren't using any js frameworks but that option isn't ruled out.
Thanks.
Upvotes: 0
Views: 2067
Reputation: 2172
Shameless plug, but here's a library I've written to handle notifications very easily: http://shaundon.github.io/simple-notifications/
Upvotes: 0
Reputation: 7183
I would recommend jQuery then you could do:
<input id='fld1' type=text value=5>
<div id="label1" style="display:none;"> </div>
<input id='fld2' type=text value=5>
and in your script
$(document).ready(function() {
$('#fld1').change(function(){
if($(this).val()>$('#fld2').val()){
//display it on the form
$('#label1').append('Fld 1 cannot be bigger than fld2!').show();
//or alert it to the user using alert();
alert('Fld 1 cannot be bigger than fld2!');
}
})
});
see http://api.fatherstorm.com/test/4168233.php
Upvotes: 1
Reputation: 3897
I guess this is what you were looking for.
Code rewritten here for your convenience
HTML
<label>A</label><input type="text" id="input1" onblur="checkBValue()"/><br/>
<label>B</label><input type="text" id="input2"/>
JS
function checkBValue(){
var b=parseInt(document.getElementById("input2").value);
var a=parseInt(document.getElementById("input1").value);
if (a<b && !isNaN(a) && !isNaN(b)) alert("A="+a+ " is less than B="+b);
return;
}
Upvotes: 1
Reputation: 6043
You can use alert
function
if(valueOfFieldA < valueOfFieldB)
{
alert('please enter amount greater than Field B');
}
Upvotes: 1
Reputation: 111
simply, you can create a js function and call it with onchange
event of the A input,
so you can specify your special way to notify user ;)
Upvotes: 0