By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

Retrieve Checkbox Value from Inline Frame

P: n/a
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[i].checked){
// populate array with checked values:
categories[i] =
iframeForm.selectedcategories[i].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.

Apr 11 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Apr 11, 2:04 pm, "Matt" <matt_marsh...@manning-napier.comwrote:
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[i].checked){
// populate array with checked values:
categories[i] =
iframeForm.selectedcategories[i].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).
Apr 11 '07 #2

P: n/a
On Apr 11, 2:26 pm, "Matt" <matt_marsh...@manning-napier.comwrote:
On Apr 11, 2:04 pm, "Matt" <matt_marsh...@manning-napier.comwrote:


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[i].checked){
// populate array with checked values:
categories[i] =
iframeForm.selectedcategories[i].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[i].checked){
// populate array with checked values:
categories[i] = iframeForm.selectedcategories[i].value;
}
}
//change array to a string for sending via form:
var categoryvalues = categories.toString();
document.scannedSearch.iframecategories.value = categoryvalues
alert(categoryvalues)
}

Apr 11 '07 #3

P: n/a
Matt wrote:
>>
>> for(var i=0; i < iframeForm.selectedcategories[].length; i++){
if(iframeForm.selectedcategories[i].checked){
// populate array with checked values:
categories[i] =
iframeForm.selectedcategories[i].value;
should be:
// populate array with checked values:
categories[categories.length] =
iframeForm.selectedcategories[i].value;
You are creating a sparse array when you use the incremental counter.
Mick
Apr 12 '07 #4

P: n/a
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.

Apr 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.