jeudi 4 août 2016

Check on checkbox, reset an input

I have

an input and a checkbox.

enter image description here


My goal

is when the user change something on the input box, I want to start showing the set to default checkbox.

Then, when the set to default checkbox is check, I want to set back the original value into that input.


Here is what I have tried

HTML

<div class="col-xs-4">
    <input id="onboard_url" value="" class="form-control" name="onboard_url" required placeholder="Ex. http://ift.tt/2aXgqoK" >
</div>

<div class="col-xs-2" style="display: none;" id="onboard_url_default">
    <input type="checkbox" id="onboard_url_default_cb" value="0" >
    Set to default
</div>


jQuery

$('#onboard_url').on('keyup', function() {
    $('#onboard_url_default').show();

    if($('#onboard_url_default_cb').prop('checked')){
        $('#onboard_url_default_cb').val(1);
        console.log('checked');
        $("#onboard_url").val('');
        $("#onboard_url").val('');
    }
});


Result

I couldn't get my console.log to print.




Aucun commentaire:

Enregistrer un commentaire