简体   繁体   中英

Input checkbox doesn't work properly after the form is submit

I have tried adding:

   <meta http-equiv="cache-control" content="max-age=0" />
   <meta http-equiv="cache-control" content="no-cache" />
   <meta http-equiv="expires" content="0" />
   <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
   <meta http-equiv="pragma" content="no-cache" />

And adding:

  'autocomplete' => 'off'

And adding:

  onload="document.getElementById('myform').reset()

On my form and html tags.

But still the checkbox doesn't work properly after the form is submitted.

What I am doing with the check-box is to enable/disable some inputs when it is selected.

$(document).ready(function(e) {

    $('#checkSpend').change(function(){
        if ($(this).is(':checked')) 
            {
                $('li.opcititycheckSpend').fadeTo(500,1);
                $('input.group1').removeAttr('disabled');
            } 
        else if ($(this).not(':checked'))
            {
                $('li.opcititycheckSpend').fadeTo(500,0.5);
                $('input.group1').attr('disabled','disabled');
            }
    })  


    $('#checkRegister').change(function(){
        if ($(this).is(':checked')) 
            {
                $('li.opcititycheckRef').fadeTo(500,1);
                $('input.checkRegistered').removeAttr('disabled');
                $('#inputFrom').focus();
            } 
        else  
            {
                $('li.opcititycheckRef').fadeTo(500,0.5);
                $('input.checkRegistered').attr('disabled','disabled');
            }
    })  


    $('#checkTopup').change(function(){
        if ($(this).is(':checked')) 
            {
                $('li.opcititycheckTopup').fadeTo(500,1);
                $('input.checktoped').removeAttr('disabled');
            } 
        else if ($(this).not(':checked'))
            {
                $('li.opcititycheckTopup').fadeTo(500,0.5);
                $('input.checktoped').attr('disabled','disabled');
            }
    })
    cache: false
});

It works properly when I reload the page.

How to make them working properly again after the form is submitted. (Because after the form is submitted, it goes to the page which has the template of the form again to resubmit the form.)

Edited:

After adding the event handlers, try trigger() :

$('#checkSpend, #checkRegister, #checkTopup').trigger('change'); //triggers given event on page load

Remove this line:

 onload="document.getElementById('myform').reset()"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM