passing checkbox values from a child form to a parent form on submit in javascript
I have the below code in a coldfusion parent form. ON click of a checkbox a child window (abc.cfm) opens which has for example 5 checkboxes related to the check box on the parent window.
<input type="checkbox" name="inq" id="inq" value="#item_code#" onClick="window.open('abc.cfm?inq=#item_code#');">#item_description#
<span class="style6">Click the checkbox for the list</span>
User checks 1 or more check boxes on the child window and hits submit ; the child page will close and The values selected need to be displayed on the parent.cfm page. Can anyone please let me know how to go about this. Im able to send the values in the textareas to the parent page. But I need the (ones that have been checked) category description to appear on the parent page.
function figure_this_out(){
var boxes = document.form1.cat;
var display = "";
var t = document.getElementById("category_id").value;
for (i = 0; i < boxes.length; i++){
if (boxes[i].checked == true){
display = display + boxes[i].value + ", ";
t = display;
//alert(t);
window.opener.document.getElementById("category_id").value=t;
window.opener.document.getElementById("narr").value = document.getElementById("narr").value;
window.opener.document.getElementById("brief").value = document.getElementById("brief").value;
}
}
window.close();
}
</script>
function figure_this_out(){
var boxes = document.form1.cat;
var display = "";
var t = document.getElementById("category_id").value;
for (i = 0; i < boxes.length; i++){
if (boxes[i].checked == true){
display = display + boxes[i].value + ", ";
t = display;
//alert(t);
window.opener.document.getElementById("category_id").value=t;
window.opener.document.getElementById("narr").value = document.getElementById("narr").value;
window.opener.document.getElementById("brief").value = document.getElementById("brief").value;
}
}
window.close();
}
</script>
That means that ONLY the *LAST* checkbox checked will have its value copied to the hidden form field. And if ANY checkbox is UN-checked, then the hidden form field value is erased.
Just plain silly. *GET RID* of that hidden form field. It is worthless.
*GET RID* of the onclick code for the checkboxes.
Then fix the code for figure_this_out. It was almost correct.
Code:
function figure_this_out()
{
var boxes = document.form1.cat;
var categories = "";
for (i = 0; i < boxes.length; i++)
{
if (boxes[i].checked)
{
if ( categories != "" ) categories += ", ";
categories += boxes[i].value;
}
}
var doc = window.opener.document;
doc.getElementById("category_id").value = categories;
doc.getElementById("narr").value = document.getElementById("narr").value;
doc.getElementById("brief").value = document.getElementById("brief").value;
window.close();
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
thanks for your reply Old pendant!. I made the changes....im able to get the values in the textareas that is the brief and the narrative from child to parent page.
I want to retrieve the "category description" of the selected checkbox to appear on my parent page. since category description is not in any html element im not able to capture its value. Can you please give your input on this? thanks!
Now the code I gave you will end up putting something like:
Code:
7$$extended widgets, 11$$crenellated nuts
into the parent's "category_id" field. The number before each $$ is the #category_id# and the stuff after each $$ is the #category_description#. With a comma-space between each such pairing.
You could then process that (either in JavaScript or in CF back-end code) by splitting on the comma-space to get the id/description pairs. And then you can split each of those pairs on the $$ to get the individual ids and descriptions.
Will that work for you? If not, then describe *HOW* you want the data to appear in the parent <form>.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
There is no input field for the category description.....on the parent page...like there are textareas for brief and narrative which get populated from child page
I need it to be displayed as a checkbox which is checked and the description on the parent page.
for example 7$$extended widgets, 11$$crenellated nuts are the values from the child page....
this is my parent page html code, the categoryId is retreived in a hidden element on parent page which is further used for processing. I wanted the cat description to be displayed like plain text. hope im clear
How do I capture the Category description? on the parent page....my question may be very dumb sorry if im ...actually ive been trying real hard to get this done....your help is greatly appreciated thanks!!
function figure_this_out()
{
var boxes = document.form1.cat;
var categories = "";
var descs = "";
for (i = 0; i < boxes.length; i++)
{
if (boxes[i].checked)
{
var pair = boxes[i].value.split("$$");
if ( categories != "" )
{
categories += ", ";
descs += "<br/>"; // OR OTHER (see below)
}
categories += pair[0];
descs += pair[1];
}
}
var doc = window.opener.document;
doc.getElementById("category_id").value = categories;
doc.getElementById("catDescriptions").innerHTML = descs;
doc.getElementById("narr").value = document.getElementById("narr").value;
doc.getElementById("brief").value = document.getElementById("brief").value;
window.close();
}
That assumed you want each category description on a separate line, so I used <br/> between each. If you want just a comma or something else between each, just change the </br/> as noted.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Failing that:
-- bring up the child page in your browser
-- click on the VIEW menu for your browser
-- click on the SOURCE or PAGE SOURCE menu item
-- copy/paste the HTML source *as seen by the browser* to here.
-- *PLEASE* wrap the code in [ code ] .... [ /code ] tags (omitting the spaces in the tags)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.