does anyone know how I can change this script around to be written into variables?
For example, OP1 = true/false, OP2, OP3 etc….
Here’s a working fiddle that was created by a helpful member of the stack community 🙂
http://jsfiddle.net/SSPax/17/
The HTML look like this:
<ul id="myUL">
<li><input type="checkbox" name="special[]" value="op1" />1</li>
<li><input type="checkbox" name="special[]" value="op2" />2</li>
<li><input type="checkbox" name="special[]" value="op3" />3</li>
</ul>
<input type="button" name="submit" value="Push Me First" id="nextquestion1" />
<input type="button" name="submit" value="Push Me Second" id="getStoredValues" />
And the script is:
$('#nextquestion1').click(function() {
$('#myUL :checkbox').each(function () {
$this = $(this);
$.data(document.body, $this.attr('value'), $this.is(':checked'));
});
});
$('#getStoredValues').click(function () {
$.each($.data(document.body), function(key, value) {
alert('Name= '+ key + ' Value= ' + value);
});
});
You can write the name-value pairs into an object. An object serves as a collection of name/value pairs. You can easily set or query it.