My project generates a table with 1000 thumbnails in it, each thumbnail image has a checkbox by it with a unique value and name. These 1000 thumbnails exist on an html page called by an iframe. My project could generate upwards 100,000 thumbnail images which I cycle through using the iframe.
I would like the user to be able to save their checkbox selections between iframes. I am just starting to code this portion. I figured I could pass the checkbox selection to the parent document in an array, which seems to work! I have a function which is called when a user checks a checkbox which gets the value, name and iframe page, it then concatenates that information and pushes it to the array. Here is the function.
parent.genL = new Array();
function repGenChk() {
var chkN = this.name;
var chkV = this.value;
var chkP = parent.document.getElementById("selOpt").selectedIndex;
var chkArr = chkN+":"+chkV+":"+chkP;
parent.genL.push(chkArr);
alert(parent.genL[parent.genL]);
}
The issue I am having is when it alerts, all of the array items are as such, ":undefined:X" X being the page number. It should look something like such for each item pushed to the array, "3041:3041:3,1002:1002:1,10294:10294:10..." so on and so forth. The only thing it is getting is the iframe page id (the selOpt variable called in the chkP variable.). I am assuming I am handling "this" wrong, but i'm not sure how I am handling it wrong? An example checkbox looks like such...
<input type="checkbox" onclick="repGenChk();" value="9059" name="9059">
So how I would like it to work is, User selects thumbnail of interest by clicking the checkbox, the checkbox function executes pushing the "x:x:x" item to the array, later one after many checks between iframe pages some other stuff gets done with that information.
Pass 'this' to repGenChk()
. As it is, you aren't passing anything to repGenChk()
and therefore this.name and this.value is undefined within the repGenChk
function.
For the input tag:
<input type="checkbox" onclick="repGenChk(this);" value="9059" name="9059">
For the repGenChk
function:
parent.genL = new Array();
function repGenChk(obj) {
var chkN = obj.name;
var chkV = obj.value;
var chkP = parent.document.getElementById("selOpt").selectedIndex;
var chkArr = chkN+":"+chkV+":"+chkP;
parent.genL.push(chkArr);
alert(parent.genL[parent.genL]);
}