samedi 22 avril 2017

Clear form fields on checkbox click

I have a form, where the user fills in their details and can check, if the billing details are the same. In that case the same data gets copied to the billing section. The script for this works just fine. However, in case the user clicks accidentally, the data should get deleted after clicking on the checkbox "billing info is different". I'm using a similar script, but instead of copying, I'm trying to add val(""). Could you please suggest, what I'm doing wrong?

Copy script:

jQuery(document).ready(function($) {
    $('input#choice_2_42_1').click(function() {
        if($(this).is(':checked')) {
            $('#input_2_35').val($('#input_2_9').val());
            $('#input_2_36').val($('#input_2_10').val());
            $('#input_2_37').val($('#input_2_4_1').val());
            $('#input_2_38').val($('#input_2_4_3').val());
            $('#input_2_39').val($('#input_2_4_5').val());
            $('#input_2_40').val($('#input_2_33').val());
            $('#input_2_41').val($('#input_2_34').val());
        };
    });
});

Erase code:

jQuery(document).erase(function($) {
    $('input#choice_2_20_1').click(function() {
        if($(this).is(':checked')) {
            $('#input_35').val("");
            $('#input_36').val("");
            $('#input_37').val("");
            $('#input_38').val("");
            $('#input_39').val("");
            $('#input_40').val("");
            $('#input_41').val("");
        };
    });
});




Aucun commentaire:

Enregistrer un commentaire