Coast Line
asked on
javscript checkbox values from popup to parent not working:
Hi i have a following code in coldfusion which is driving me crazy:
in my page i have something like this:
<cfform method="post" action="#cgi.SCRIPT_NAME#? #cgi.QUERY _STRING#" name="post_sell_offer" id="post_sell_offer">
<input name="sel_cat" class="tinyborder" type="button" value="Select Category" onclick="WinOpen('category _select.cf m?frm=post _sell_offe r&txt=sel_ cats','650 ','540');" >
<input type="button" name="remove_selected" value="Remove Selected" onclick="return removeSelected();" class="button"><br><br />
<select id="sel_cats" name="sel_cats[]" size="5" multiple style="height: 100px; width: 250px;">
</select>
</cfform>
Now on clicking category_select.cfm page opens! The code related to category_select.cfm is below!
in my page i have something like this:
<cfform method="post" action="#cgi.SCRIPT_NAME#?
<input name="sel_cat" class="tinyborder" type="button" value="Select Category" onclick="WinOpen('category
<input type="button" name="remove_selected" value="Remove Selected" onclick="return removeSelected();" class="button"><br><br />
<select id="sel_cats" name="sel_cats[]" size="5" multiple style="height: 100px; width: 250px;">
</select>
</cfform>
Now on clicking category_select.cfm page opens! The code related to category_select.cfm is below!
<script language="javascript1.2">
function checkMaxSelection( chk , rtnForm , rtn )
{
if (chk.checked )
{
var theForm = document.frmCats; var z = 0; var sel=0;
var p = window.opener || parent;
ddl = p.document.forms[rtnForm].elements[rtn];
total = ddl.options.length;
//loop through each element and count the checkbox that are checked
while (theForm[z])
{
if (theForm[z].type == 'checkbox' && theForm[z].checked) { sel++; }
z++;
}
//then see if it is less than the max selection allowed
if (sel > 3 - total)
{
alert('More Categories selected than allowed');
return false;
}
}
return true;
}
function addSelected( rtnForm , rtn )
{
var p = window.opener || parent;
ddl = p.document.forms[rtnForm].elements[rtn];
total = ddl.options.length;
if (total >= 3 ) { alert("More Categories selected than allowed"); return false;}
var theForm = document.frmCats; var z = 0;
//loop through each element and if its a checkbox and cheked add to the parent's listBox
while (theForm[z])
{
if ( theForm[z].type == 'checkbox' && theForm[z].checked )
{
//loop through listbox and add only if not found previously
found = false;
for(i=0; i < 3 - total; i++)
if (ddl.options[i] != null)
if (ddl.options[i].value == theForm[z].value) found = true;
if ( !found )
{
ddl.options.length++;
ddl.options[total].text = theForm[z].title;
ddl.options[total].value = theForm[z].value;
ddl.options[total].selected = true;
}
total = ddl.options.length;
}
z++;
}
return true;
}
</script>
Now in below we have the following
<cfset getSelectedValues = #tools.getCats(checkpost=val(url.catID))#>
<form method="post" action="mode.cfm?action=selloffer_showkeywordcats&catID=<cfoutput>#val(catID)#</cfoutput>" name="frmCats">
<input type="hidden" name="txt" value="sel_cats">
<input type="hidden" name="frm" value="post_sell_offer">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<cfif getSelectedValues.recordcount>
<cfoutput query="getSelectedValues">
<tr>
<td><input type="checkbox" name="chkcat[]" value="#catID#" onClick="return checkMaxSelection(this,'post_sell_offer','sel_cats');"> #catName#</td>
</tr>
</cfoutput>
<tr><td> </td></tr>
<tr><td>
<input type="submit" value=" Add Selected " name="done" class="tinyborder">
<input type="button" value=" Close Window " onClick="window.close();" name="close" class="tinyborder">
</td></tr>
<script language="javascript">
addSelected('post_sell_offer','sel_cats');
</script>
</form>
now my selected category items never get added in the parent Page!
Please guide me what i am doing wrong here!
ASKER
I think you did nt read my question properly!
the popup opens and i can perform functions but when i click the checkbox and then click add selected, they did not get added to parent page while in my function above addselected it is doing it as such!
the popup opens and i can perform functions but when i click the checkbox and then click add selected, they did not get added to parent page while in my function above addselected it is doing it as such!
Hi again
yes, I didn't understand your initial question, that's why I asked for clarification.
I'll take a look now and let you know.
yes, I didn't understand your initial question, that's why I asked for clarification.
I'll take a look now and let you know.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hmm! what we submit the data to the same page instead of going to mode.cfm page
in the meantime i try your solution!
in the meantime i try your solution!
Hi again
in order to call the javascript function properly, you must either do it before the form is submitted (like in my reply), submit the form via JavaScript too, or finally, not refresh the page at all and use an Ajax call in order to post the data to the processing script. Let me know if my solution above worked ok or if we need to investigate further.
in order to call the javascript function properly, you must either do it before the form is submitted (like in my reply), submit the form via JavaScript too, or finally, not refresh the page at all and use an Ajax call in order to post the data to the processing script. Let me know if my solution above worked ok or if we need to investigate further.
ASKER
i think ur solution did worked, but the categories does appear in parent window but not visible
here are some screenshots:
Untitled.png
here are some screenshots:
Untitled.png
ASKER
we need furthur investigation as we are near the end but some things creating trouble!
Hi again
I was away and couldn't follow up on your comments yesterday. I'll take a look now and let you know.
I was away and couldn't follow up on your comments yesterday. I'll take a look now and let you know.
ASKER
yep! ok so should we move ahead in our conversation of this error
[off-topic]
the question begs to be asked is: why, in year 2010, are you still using pop-up windows?
it's not that pretty much every modern browser blocks them by default, but there are much nicer alternatives like ui dialogs (floated divs)
Azadi
the question begs to be asked is: why, in year 2010, are you still using pop-up windows?
it's not that pretty much every modern browser blocks them by default, but there are much nicer alternatives like ui dialogs (floated divs)
Azadi
ASKER
Hmm! Nice point Azadi But the Reason i am using is like i am noob in javascript and other thing is i am creating a subcategory selection based on the values selected in the popup window so i get this thing running up! then later it can be thuoght to be converted in a UI
UI dialog u mean by!!!!!????????
UI dialog u mean by!!!!!????????
>> UI dialog u mean by!!!!!????????
like <cfwindow>.
or, better yet, jquery UI dialog (http://jqueryui.com/demos/dialog/)
Azadi
like <cfwindow>.
or, better yet, jquery UI dialog (http://jqueryui.com/demos/dialog/)
Azadi
ASKER
leaving cfwindow behind we can move ahead with popup now!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
you say that when you click the inputbox, the category_select.cfm page opens. That is normal since you have added: onclick="WinOpen('category
What is the behavior that you expect if it isn't the current one?