Alex
Alex

Reputation: 1733

Javascript Notification Pop-up?

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

Answers (6)

shauneba
shauneba

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

FatherStorm
FatherStorm

Reputation: 7183

I would recommend jQuery then you could do:

   <input id='fld1' type=text value=5>
   <div id="label1" style="display:none;">&nbsp;</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

Philar
Philar

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

Zain Shaikh
Zain Shaikh

Reputation: 6043

You can use alert function

if(valueOfFieldA < valueOfFieldB)
{
    alert('please enter amount greater than Field B');
}

Upvotes: 1

Mohammad
Mohammad

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

user506069
user506069

Reputation: 781

You might try using the alert function.

Upvotes: 1

Related Questions