user3377703
user3377703

Reputation:

how to remove text box value on check box unchecked?

Hi i have two check boxes PlanA AND AndroidApps and one textbox when i checked check box then text box enable and when i unchecked thrn text dox disabled but problem is when tex box is enable and i write something in text box and then unchecked my checkbox then my textbox disabled but that text which i typed it does not delete and text box does not clear

Here is my code

<!DOCTYPE html>
<html>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#main_box').on('change',function(e) {
        console.log("dfsd");
       $("#a2").prop("checked",this.checked);
     $("#emailid").prop("disabled", !$(this).is(':checked'));
    });
});
</script>
</head>

<body>

                <input id="main_box"type="checkbox" name="PlanA" value="A"><label for="PlanA"><span style="font-weight:bold">PlanA</span></label><br>
                <input name="PlanA" type="hidden" value=0 />


                <input type="checkbox" name="AndroidApps" id="a2" value=1><label for="AndroidApps"><span style="font-weight:bold">AndroidApps</span></label><br>
                <input name="AndroidApps" type="hidden" value=0 />


                         <input type="text" name="emailid"id="emailid"disabled="disabled" required size="45"  >

</body>
</html>

How can i achieve this

Thanks in advance

Upvotes: 0

Views: 5405

Answers (4)

Sai Avinash
Sai Avinash

Reputation: 4753

You can use val() to set the value of your input:

$("#emailid").val('');

and if your are retrieving values, you use:

$(selector).val()

Don't get confused with those two

Hope this helps..

Upvotes: 0

Rahul
Rahul

Reputation: 2307

Use this Link:: http://jsfiddle.net/rjha999/DM9b9/

contains code for checkbox check ::

$("#chk").click(function(){
     if($("#chk").is(":checked"))
     {
        $("#txt").val('');
     }
})

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Add a condition

$(document).ready(function () {
    $('#main_box').on('change', function (e) {
        $("#a2").prop("checked", this.checked);
        $("#emailid").prop("disabled", !this.checked);
        if(!this.checked){
            $("#emailid").val('');
        }
    });
});

Demo: Fiddle

Upvotes: 1

Felix
Felix

Reputation: 38102

You can use val() to set the value of your input:

$("#emailid").val('');

Updated Fiddle

Upvotes: 1

Related Questions