0

I have some javascript that on page load reads a group of check boxes checking their checked status. If the checkbox is checked then a value is added to an array which is later used.

var _chkBoxes = document.getElementsByName("chkProduct");
var _chkBoxesLen = _chkBoxes.length;
var _chkArray = [];

for (var i = 0; i < _chkBoxesLen; i++) {

    if (_chkBoxes[i].checked === true) {
        _chkArray.push(_chkBoxes[i].id.split("-")[1]);
        console.log(_chkArray);
    }
}

This works fine for all browsers when the page is freshly loaded.

However in IE if a user ticks some boxes, navigates to another page then pushes the back button then this work does not recognise that checkboxes have been previously checked, even though on the page they are.

Is this a bug with IE and whats the fix, any opinions appreciated!

1 Answer 1

0

This is a feature in the browser, and other browsers than IE does this in a similar way, so the problem is most likely not isolated to IE.

When you go back, the browser loads the page and then automatically fills the form with the previous data. You have to make sure that the script runs after the browser has added the data to the form, or it won't notice the change.

Sign up to request clarification or add additional context in comments.

2 Comments

yes that figures. Whats the best way to delay this script until the data has been added? Due to the templated nature of this site the script gets called just after the associated form is closed.
@user502014: You can try to use the onload event.

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.