Retrieve Checkbox Value from Inline Frame

M

Matt

I am no JavaScript guru so please bear with me and be as detailed as
possible with your response. I thank you in advance.

I have an ASP page that contains form elements. I also have an inline
frame on this page that contains multiple checkboxes with the same
name/id. This is a search form and users need the ability to select
which categories they would like to search for. I have to put the
categories in an inline frame to save real estate on the screen.

What I need to do is submit the main form and also pass the inline
frames checkbox values to the forms processing page. I figured I could
handle the onClick event of the submit button (which is part of the
main form and not within the inline frame) to set a hidden field value
with a string value of all the checked option values from the inline
frame's form on the main form. Then submit the form via JavaScript to
the processing page. I would then be able to access the checkbox
values via the hidden field on my forms processing page.

I am having a problem accessing the inline frame's checkbox values and
populating them into a string. I have cut together a couple scripts I
found online but have had no luck. Here is the script I put together.

function showValues(){

var iframe = document.getElementById("categories");
var iframeDoc = iframe.document;
var iframeForm = iframeDoc.getElementById("SelectCategories");

//create array to hold values of checked 'selectedcategories' items:
var categories = new Array();

for(var i=0; i < iframeForm.selectedcategories[].length; i++){
if(iframeForm.selectedcategories.checked){
// populate array with checked values:
categories =
iframeForm.selectedcategories.value;
}
}
//change array to a string for sending via form:
var categoryvalues = categories.toString();
document.scannedSearch.iframecategories.value = categoryvalues
//alert(categoryvalues)
}

Description:
categories = the name/id of the inline frame
SelectCategories = the name/id of the form within the inline frame
selectedcategories = the name/id of the checkboxes within the inline
frame
ScannedSearch = the name/id of the main form
iframecategories = the name/id of the hidden form field on the main
form

I receive the following error on the "for" line:
"Syntax Error"

Please let me know if you require any further information and thank
you for your assistance.
 
M

Matt

I am no JavaScript guru so please bear with me and be as detailed as
possible with your response. I thank you in advance.

I have an ASP page that contains form elements. I also have an inline
frame on this page that contains multiple checkboxes with the same
name/id. This is a search form and users need the ability to select
which categories they would like to search for. I have to put the
categories in an inline frame to save real estate on the screen.

What I need to do is submit the main form and also pass the inline
frames checkbox values to the forms processing page. I figured I could
handle the onClick event of the submit button (which is part of the
main form and not within the inline frame) to set a hidden field value
with a string value of all the checked option values from the inline
frame's form on the main form. Then submit the form via JavaScript to
the processing page. I would then be able to access the checkbox
values via the hidden field on my forms processing page.

I am having a problem accessing the inline frame's checkbox values and
populating them into a string. I have cut together a couple scripts I
found online but have had no luck. Here is the script I put together.

function showValues(){

var iframe = document.getElementById("categories");
var iframeDoc = iframe.document;
var iframeForm = iframeDoc.getElementById("SelectCategories");

//create array to hold values of checked 'selectedcategories' items:
var categories = new Array();

for(var i=0; i < iframeForm.selectedcategories[].length; i++){
if(iframeForm.selectedcategories.checked){
// populate array with checked values:
categories =
iframeForm.selectedcategories.value;
}
}
//change array to a string for sending via form:
var categoryvalues = categories.toString();
document.scannedSearch.iframecategories.value = categoryvalues
//alert(categoryvalues)

}

Description:
categories = the name/id of the inline frame
SelectCategories = the name/id of the form within the inline frame
selectedcategories = the name/id of the checkboxes within the inline
frame
ScannedSearch = the name/id of the main form
iframecategories = the name/id of the hidden form field on the main
form

I receive the following error on the "for" line:
"Syntax Error"

Please let me know if you require any further information and thank
you for your assistance.


I think I figured out the Syntax Error. I removed the [] on the for
line. Now I am receiving an "Object required" error on the same line
at char 18. My new line is:

for(var i=0; i < iframeForm.selectedcategories.length; i++){

I assume it is not recognizing either (or both) the inline frame form
and checkbox element).
 
M

Matt

I am no JavaScript guru so please bear with me and be as detailed as
possible with your response. I thank you in advance.
I have an ASP page that contains form elements. I also have an inline
frame on this page that contains multiple checkboxes with the same
name/id. This is a search form and users need the ability to select
which categories they would like to search for. I have to put the
categories in an inline frame to save real estate on the screen.
What I need to do is submit the main form and also pass the inline
frames checkbox values to the forms processing page. I figured I could
handle the onClick event of the submit button (which is part of the
main form and not within the inline frame) to set a hidden field value
with a string value of all the checked option values from the inline
frame's form on the main form. Then submit the form via JavaScript to
the processing page. I would then be able to access the checkbox
values via the hidden field on my forms processing page.
I am having a problem accessing the inline frame's checkbox values and
populating them into a string. I have cut together a couple scripts I
found online but have had no luck. Here is the script I put together.
function showValues(){
var iframe = document.getElementById("categories");
var iframeDoc = iframe.document;
var iframeForm = iframeDoc.getElementById("SelectCategories");
//create array to hold values of checked 'selectedcategories' items:
var categories = new Array();
for(var i=0; i < iframeForm.selectedcategories[].length; i++){
if(iframeForm.selectedcategories.checked){
// populate array with checked values:
categories =
iframeForm.selectedcategories.value;
}
}
//change array to a string for sending via form:
var categoryvalues = categories.toString();
document.scannedSearch.iframecategories.value = categoryvalues
//alert(categoryvalues)

Description:
categories = the name/id of the inline frame
SelectCategories = the name/id of the form within the inline frame
selectedcategories = the name/id of the checkboxes within the inline
frame
ScannedSearch = the name/id of the main form
iframecategories = the name/id of the hidden form field on the main
form

I receive the following error on the "for" line:
"Syntax Error"
Please let me know if you require any further information and thank
you for your assistance.

I think I figured out the Syntax Error. I removed the [] on the for
line. Now I am receiving an "Object required" error on the same line
at char 18. My new line is:

for(var i=0; i < iframeForm.selectedcategories.length; i++){

I assume it is not recognizing either (or both) the inline frame form
and checkbox element).- Hide quoted text -

- Show quoted text -


Sorry everyone. I figured it out. The issue was the way I was trying
to access the iFrame. Here is my updated script in case you are
interested. Sorry about the premature positng. I had to step away from
it for a while to figure it out.

function showValues(p_frame, p_fieldname){

var iframeForm =
window.frames["categories"].document.SelectCategories;

//create array to hold values of checked 'delete_this' items:
var categories = new Array();
for(var i=0; i < iframeForm.selectedcategories.length; i++){
if(iframeForm.selectedcategories.checked){
// populate array with checked values:
categories = iframeForm.selectedcategories.value;
}
}
//change array to a string for sending via form:
var categoryvalues = categories.toString();
document.scannedSearch.iframecategories.value = categoryvalues
alert(categoryvalues)
}
 
M

Mike B.

for(var i=0; i < iframeForm.selectedcategories[].length; i++){

The first thing to do: remove the [] before the ".length" check, so
the line should read:
for(var i=0; i < iframeForm.selectedcategories.length; i++){

there may be more errors, but that is the most obvious that I see.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top