0

How to clear the value of input id "price" and disable it when clicking on radio button id "meta_price_type_0" ,"meta_price_type_1",meta_price_type_2

 <input id="price" type="text" name="price" value="200" >
 <input type="radio" name="meta[4]" id="meta_price_type_0" value="Has Price Above0">
 <input type="radio" name="meta[4]" id="meta_price_type_1" value="Has Price Above1">
 <input type="radio" name="meta[4]" id="meta_price_type_2" value="Has Price Above2">
2
  • Hi regent I tried this for first id $("input:radio[id=meta_price_type_0]").click(function(){ $('#price').val(''); }); Commented Aug 21, 2014 at 11:51
  • @govindak, try $("#meta_price_type_0").click(function(){ $('#price').val(''); }); Commented Aug 21, 2014 at 11:52

4 Answers 4

2

Try this :

$("#meta_price_type_0, #meta_price_type_1, #meta_price_type_3").click(function(){
    $("#price").val("");
    $("#price").attr("disabled", true);
              OR (use either)
    $("#price").prop("disabled", true);
});
Sign up to request clarification or add additional context in comments.

4 Comments

You forgot to disable input
.attr("disabled", true) will work on js less than 1.6
Cant you guys see $("#price").prop("disabled", true); in my answer ????????? Strange...
@Yunus I wanted to point out that it should be $("#price").attr("disabled", "disabled");, but it turns out that $("#price").attr("disabled", true); works aswell
0

you can do that on this way:

$('#meta_price_type_0, #meta_price_type_1, #meta_price_type_2').click(function(){
     $('#price').val('').attr('disabled', 'true');
});

Or you can put a class in each input radio, this will allow you to work with a more understanding jquery and you can use other elements to do the same...

<input type="radio" name="meta[4]" value="Has Price Above0" class="clear-the-price">
<input type="radio" name="meta[4]" value="Has Price Above1" class="clear-the-price">
<input type="radio" name="meta[4]" value="Has Price Above2" class="clear-the-price">

And your jquery selector will be like:

$('input.clear-the-price').click(function(){
    $('#price').val('').attr('disabled', 'true');
});

Here is a jsfiddle where you can se this script in action: http://jsfiddle.net/w9a8u4f2/

Comments

0
$( "input[type='radio'][name*='meta']" ).on( "click", function ( ) {

    $( "#price" ).val( "" );
    $( "#price" ).prop( "disabled", true );


});

DEMO: http://jsfiddle.net/kxtvmm1m/

Comments

0
$('input[type="radio"]').on('click',function(){
    $("#price").val("").prop('disabled',true);
});

If you have other inputs with type="radio" you might wanna use the following code.

$('input[id*="meta_price_type_"]').on('click',function(){
    $("#price").val("").prop('disabled',true);
});

2 Comments

@ Maveric - What if the user clicks on the first radio itself with ID price ..???? don't you think even that will disable the first radio option... ??
The input with id="price" is of type="text"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.