Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use checkbox field in pop-up window to populate opener

Status
Not open for further replies.

Jawa

Programmer
Feb 21, 2002
74
US
I have a page with a text field. On this page I can click a link and open a window with a series of checkboxes. What I would like to do is be able to check off the boxes and insert the values into the text field of the opener page. I would like the values to insert as a comma seperated list.

Can someone point me in the right direction?

Thank you.
 
window.opener.document.<form-name>.<field-name>.value should get you a reference to the value of the text field you want to populate. Retrieve its current value, add or subtract from it whichever bit of text is associated with the checkbox which has just been accessed, then put back the new value.

If you need more detail than this, I'll knock up some sample code when I have more time...
 
Thank you for the quick reply.

So I will own up to being a little lost. Here is where I am. Following is a test page that has the input box I wish to populate with a comma seperated list of values from the the popup window:


<form action="" method="post" name="orderform" id="test">
<a href="_insertProduct.cfm" onclick="window.open(this.href,'window','params');return false">open the window with check boxes</a><br>
<input type="text" name="sku" value="">skus to be populated from window with checkboxes
</form>


This is an example of the popup window with checkboxes:


<form action="" method="post" name="products" id="products">
<input type="checkbox" name="product" value="51"> Amethyst and Iolite Necklace with Lilac Quartz Pendant<br>
<input type="checkbox" name="product" value="52"> Apricot Pearl Necklace with Gold Foil Pendant<br>
<input type="checkbox" name="product" value="63"> Asian Inspired Round Cinnabar Necklace<br>
<input type="checkbox" name="product" value="95"> Blue Crystal and Ivory Pearl Choker<br>
<input type="submit" value="update" name="update">
</form>


So I guess my question is can you point me on how to get the values from this popup in to the input area as a comma seperated list?

THANK YOU!!!!!!
 
OK I have gotten this far to place this snippet of code in the checkbox area to poulate the input box:

javascript:eek:pener.document.orderform.sku.value=document.products.product.value;

But I am still unsure about how to make it a comma list in the input box?
 
I have just made allmost the same. I did it like this:
Code:
<script>
<!--
function doServices(){
	var generator=window.open(','wdwServices','fullscreen=no,toolbar=no,
status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,
location=no,width=400,height=500,left=220,top=130');

generator.document.writeln('<html><head><title>SLA - Services</title>');
generator.document.writeln('<script type="text/javascript">');
generator.document.writeln('function check(){');
generator.document.writeln('infoservices = document.forms[0].elements');
generator.document.writeln('inp_services = self.opener.document.form_tilfoej.inp_services');
generator.document.writeln('txt=""');
generator.document.writeln('for (i=0;i < infoservices.length; i++){');
generator.document.writeln('if (infoservices[i].checked){');
generator.document.writeln('txt += infoservices[i].value + "\\n" }');
generator.document.writeln('inp_services.value = txt');
generator.document.writeln('} self.close() }');
generator.document.writeln('</script>');
generator.document.writeln('</head><body style="font-family:verdana,arial,helvetica,sans-serif;">');
generator.document.writeln('<font size="3"><b>Vælg Services</b></font><br><br><form>');
generator.document.writeln(\'<p><font size=\"2\"><input type="checkbox" value=\"'.$row[1].'\">&nbsp;'.$row[1].'</font></p>\');
generator.document.writeln('<input type="button" value="  OK  " onclick="check(this)"></form>');
generator.document.writeln('</body></html>');
generator.document.close();
}
//-->
</script>

There is a small bit of php (the row things in the checkboxes). Hope this can help.

staffa
 
The code is implementet in the opener page, and i just saw a error in my code above:

"var" is the start of the window.open line

var generator=window.open ect....

staffa
 
And i nearly forgot that you have to change \\n to a comma to get the comma seperation.

staffa
 
Here's a quick possibility for an onClick and/or onSubmit handler for your example:
Code:
function updateSku() {
 var t = '';
 for (var i in this.form.product) {
  if (this.form.product[i].checked) {
   t += (t == '' ? '' : ',') + this.form.product[i].value;
  }
 }
 window.opener.document.orderform.sku.value = t;
}
...
<input type="checkbox" name="product" onClick="updateSku()" ...>
...
<input type="submit" value="update" name="update" onSubmit="updateSku(); window.close(); return false;">
The onClick for the checkboxes isn't strictly necessary, but it keeps the value updated in case the user closes the window instead of pressing the update button. Of course, this may not be a desired behaviour; you'll have to decide that for yourself.
 
WOW, this is a great education thanks!!

MOrac I tried your solution, but the value is not being inserted. I am using the onClick method. I tried altering the loop, but could nt get it to work. THANKS!!
 
OK, got it to work with



<script language="JavaScript">
function updateSku() {
//var loopVal = this.form.product;
var t = '';
//for (var i in this.form.product) {
for (i=0;i < document.products.elements.length; i++){
if (document.products.elements.checked) {
t += (t == '' ? '' : ',') + document.products.elements.value;
}
}
window.opener.document.orderform.sku.value = t;
}
</script>

 
OK, I have an extension to this thread. what I would like to do is have the opener automatically submitted once the list of skus have been populated. Hopefully this is possible

Any help would be greatly appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top