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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putting checked values into a var to send to parent wind 1

Status
Not open for further replies.

ShamanFR

Programmer
Sep 20, 2005
9
FR
Ok I have a pop up window that comes up with a list of items with checkboxes and I wanted to know how I can get all those checked items put into a variable to send back to the parent window open click on a done button? Lets say I have colors for example. Red, Green, Blue, Yellow, Black and I check Red, Blue, Yellow is there a way to get those into a variable so that I can send the var back to the parent window into a text field?

Nick
 
Sure... if you're opening the window using the window.open() method then you can write directly to the parent window through the window.opener property of your popup window.

For other methods of opening a popup window there are other ways of doing it, but this is the most common.


Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Yea I am opening the window with the window.opein() method, but I dont want to add all the colors with the onChange method. I am currently doing that and it is not working well. What I would like to check all the checkbox and then click on a button and have that button call a function. The only thing is that I dont know how to get all the checkbox values in the function. I am geussing that I would be doing somethinglike this for the function.


<!--Begin
// Add the selected items in the parent by calling method of parent
function addToParentWin() {
window.opener.itemsForm.colors.value='';
window.close();
}
// End -->
</SCRIPT>
</head>

<body>

<center>
<form method='post'>
<table>
<tr>
<td align='center'><input type='checkbox' vlaue='Red,&nbsp;'> Red </td>
</tr>
<tr>
<td align='center'><input type='checkbox' vlaue='black,&nbsp;'> Black </td>
</tr>
<tr>
<td align='center'><input type='checkbox' vlaue='blue,&nbsp;'> blue </td>
</tr>
<tr>
<td align='center'><input type='button' vlaue='blue,&nbsp;' onClick='addToParentWin()'> blue </td>
</tr>
</table>
</form>
</center>

But the only probelm is that I dont know how to get all the checked items into the value.

Nick
 
Code:
<!--Begin
// Add the selected items in the parent by calling method of parent
function addToParentWin() {
var arrColours = new Array();
var allBoxes = document.body.getElementsByTagName("input");
for(var i = 0; i < allBoxes.length; i++){
 if(allBoxes.item(i).type == 'checkbox' && allBoxes.item(i).checked){
  arrColours[arrColours.length] = allBoxes.item(i).value;
 }
}

window.opener.itemsForm.colors.value=arrColours.join(", ");
window.close();
}
// End -->
</SCRIPT>
</head>

<body>

<center>
<form method='post'>
<table>
<tr>
<td align='center'><input type='checkbox' [b]value[/b]='Red'> Red </td>
</tr>
<tr>
<td align='center'><input type='checkbox' [b]value[/b]='black'> Black </td>
</tr>
<tr>
<td align='center'><input type='checkbox' [b]value[/b]='blue'> blue </td>
</tr>
<tr>
<td align='center'><input type='button' onClick='addToParentWin()'> blue </td>
</tr>
</table>
</form>
</center>

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Thank you soooooooooooooo much. You don't know how long I have been searching and asking around forums on how to do this, and you helped me out in no time what so ever. Thank you again. [thumbsup]

Nick
 
FYI: One acceptable way of saying "thank you" in these forums is to click on that link at the bottom of the post that says "Thank drarfthrower for this valuable post!"


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Except the link says "dwarfthrower", not "drarfthrower". [blush]

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
It's not too late.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top