1

So, quick question - I check to see if a checkbox is clicked on an html doc and then when the user clicks on a continue button, it takes them to the next page, which will do stuff based on whether or not that checkbox was checked. What's the easiest way of doing this?

In the index.html file (homepage) I have

 if ($("#checkArray").is(":checked")) {
 console.log("permission granted");
 } else {
 console.log("No permissions granted");
 }
window.location='/auth/facebook';

which checks to see if the check box is marked. it then goes to the next html document (confirmation.html) for authorization of facebook here, I want to call a function if the checkbox was checked (true).

Please help! Thanks!!

asked Aug 10, 2014 at 23:19
3
  • 2
    You can add a query parameter to the URL if the checkbox was checked, and test for its existence on the other page. Commented Aug 10, 2014 at 23:22
  • That would be pretty easy to just mess with I'd think Felix Commented Aug 10, 2014 at 23:23
  • Do you think its wise to seperate this checkbox stuff in another page thats used for authentication? Commented Aug 10, 2014 at 23:24

2 Answers 2

2

You can use cookies or sessionStorage.

Example with SessionStorage:

if ($("#checkArray").is(":checked")) {
 window.sessionStorage.setItem('checked', true);
} else {
 window.sessionStorage.setItem('checked', false);
}
window.location='/auth/facebook';

And on other page:

var checked = window.sessionStorage.getItem('checked');

SessionStorage works with modern browsers so if you need to support old browsers like IE8, you should use cookies. You can read more about cookies here: http://www.w3schools.com/js/js_cookies.asp.

answered Aug 10, 2014 at 23:27
Sign up to request clarification or add additional context in comments.

Comments

0

Following Felix Kling

Try

at index.html

$("input[type='button']").on("click", function(e) {
 var checked = $("input[type='checkbox']").prop("checked");
 if (checked) {
 // do stuff
 // if `_checked` === true
 console.log(checked); 
 } 
 else {
 // do stuff
 // if `_checked` === false
 console.log(checked)
 };
 var conf = window.location.href;
 window.location.href = conf + "?checked=" + checked;
});

at confirmation.html

$(window).on("load", function(e) {
 var _checked = (e.target.location.href
 .split("?").slice(1,2)[0].split("=")[1] === "true" 
 ? true 
 : false
 );
 if(_checked) {
 // do stuff
 // if `_checked` === true
 console.log(_checked);
 } else {
 // do stuff
 // if `_checked` === false
 };
});

jsfiddle http://jsfiddle.net/guest271314/j9t598ab/

answered Aug 11, 2014 at 0:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.