hi, im having a problem using this jquery
I mamanged it to g and fetch data from mysql n now i want it to disply only one class at a time on available or not available
here is the js

$(document).ready(function(e) {

    function check_availability()
    var new_Auction =$('#txtAuction').val();
             $('h4.alert_success').html(new_Auction + ' is Available');  
            }   $('h4.alert_error').html(new_Auction + ' is not available'); 



it is working fine, exept that it shows me both the class.
please healp

thank you a lot

4 Years
Discussion Span
Last Post by Airshow

If you are checking every time the keyup event fires, then at some point, I would imagine that both blocks of code in your If..else will run. So, for example, say the first time you pass through the if..then and its false, the h4.alert_error runs, and you change the display property to block. On the next keyup, its true so the h4.alert_success block runs. Now you have both showing on the screen.


Well, maybe in the success section add..

Then in the error section add...


Displaying the right message requires a fairly trivial reorganisation of the code.

Another, more significant problem is that sequential ajax responses are not guaranteed to arrive back in the same order as the requests were sent. This is particularly likely when requests are issued rapidly (eg. in response to key strokes) and could result in the wrong message being displayed agaonst the current value of #txtAuction.

This potential problem can be overcome by rejecting the immediately previous request before making a new one.

Try this :

$(document).ready(function(e) {

    var chk_avail_xhr = null; //variable for storing the latest request.

    $('#txtAuction').on('keyup', function() {
        var new_Auction = $(this).val();
        if(chk_avail_xhr) {
            chk_avail_xhr.reject(); //inhibit processing of a successful response from the previous request.
        chk_avail_xhr = $.post(
            { txtAuc: new_Auction },
            function(result, textStatus, jqXHR) {
                var text = (parseInt(result) == 1) ? ' is Available' : ' is not Available';
                $('h4.alert_success').text(new_Auction + text).show();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.