show() & hide()

show() & hide()

im tring to show and hide input fields based on option selection...i'm trying to get it to work when page loads as well as on change...the code below doesn't work at all if anyone can point me in the right direction or help please...thank you

  1. $(function()
    {
        var listing_value = $("select[name='listing']").text();
       
        if (listing_value == "Auction")
        {
            $("label[for='price']").hide();
            $("input[name='price']").hide();
            $("label[for='offers']").hide();
            $("input[name='offers']").hide();
            $("label[for='quanity']").hide();
            $("input[name='quanity']").hide();
           
            $("label[for='starting_price']").show();
            $("input[name='start_price']").show();
            $("label[for='buy_now']").show();
            $("input[name='buy_now']").show();
            $("label[for='buy_now_price']").show();
            $("input[name='buy_now_price']").show();
        }
        else if (listing_value == "Buy Now")
        {
            $("label[for='starting_price']").hide();
            $("input[name='start_price']").hide();
            $("label[for='buy_now']").hide();
            $("input[name='buy_now']").hide();
            $("label[for='buy_now_price']").hide();
            $("input[name='buy_now_price']").hide();
           
            $("label[for='price']").show();
            $("input[name='price']").show();
            $("label[for='offers']").show();
            $("input[name='offers']").show();
            $("label[for='quanity']").show();
            $("input[name='quanity']").show();
        }
    });