2

I have the following jquery, what is letting the user to fill out additional fields in the form if the check box is checked. What I want is to clear the additional inputs fields values if the check box is unchecked.

$(document).ready(function() {
    $('input:checkbox').attr('checked', false);
    $('#xml').hide();
    $('#checkbox').click(function() {
        $('#xml')[this.checked ? "show" : "hide"]();
    });
    $('input[type="checkbox"]').click(function() {
        if (this.checked) {
            $('div#xml p label input').attr('required', true);
        }

        else

            $('div#xml p label input').removeAttr('required', true);

        //Here should the corresponding code to be pasted 
                   //$('div#xml p label input').val = ('');

    });

$(function() {
    $("#datepicker").datepicker();
});
});

3 Answers 3

3

The solution is:

 $('div#xml p label input').val("");
Sign up to request clarification or add additional context in comments.

Comments

0

You should do

$('input[type="checkbox"]').click(function() {
    if (this.checked) {
        $('div#xml p label input').attr('required', true);
    }else{
        $('div#xml p label input').removeAttr('required', true);
        $('div#xml p label input').val('');
    }

});

Comments

0

Another working solution:

<script type="text/javascript">
$(document).ready(function(){
    $('#pizzaOption>input[type="checkbox"]').click(function() {
      if ($(this).is(':checked')) {
    var pizzaPrice=$(this).closest("#pizzaOption").data('price');
     console.log(price);
       $('#total').html(pizzaPrice);
    } else {
      var pizzaPrice=0;
      $('#total').html(pizzaPrice);
    }
    });
});
  </script>

Comments

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.