This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Sending value from popup to parent window

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I open up a search page as a pop up window. The user implements the search options and is returnded a number of rows. The user then selects one of these rows using a check box which I have defined as a multibox in my jsp.

The problem I have is populating the field on the parent window with the value of the multibox?

In the JSP i define my multibox as such

<html:multibox name="actionClientForm" property="resourceIds">
<bean:write name="client" property="resourceId"/>
</html:multibox>

The link to close this page and send the value is as follows:

<td align="right">
<html:link href="javascript:sendValue();">Add Client</html:link>
</td>

The javascript function:

<script language="JavaScript">
function sendValue(s)
{

var selvalue = s
out.println("variable = " + selvalue");
window.opener.document.createClnForm.clientId.value = selvalue;
window.close();
}
</script>

If I put a value of 1 in the link where i call the javascript it works.
<td align="right">
<html:link href="javascript:sendValue(1);">Add Client</html:link>
</td>

However what i want to send back is the
<bean:write name="client" property="resourceId"/> of the selected multibox.

i tried using bean define but that did not seem to work.

The property resourceIds of the actionClientForm is a collection.

Anyone know how to do this?

thanks
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you are using javascript in a Struts jsp, it's important to remember that your javascript code is operating on the "rendered" html page. This means that you need to work with the plain old HTML tags that are generated by the Struts tags, not the struts tags themselves. The best way to see how the Struts tags have been rendered is by using your browser's "view source" option.

When you do this with your page, you will see that a number of tags have been generated:
<input type="checkbox" name="resourceIds" value="xx">
Where xx is the resource ID.

Your javascript has to do the following:
  • Get an array of all the resourceIds checkboxes. hint: var checkBoxes = document.myform.resourceIds;
  • Iterate over that array, and create a new array of resource Ids containing only IDs for controls that were checked. hint: if (checkBoxes[i].checked) newArray[j++] = checkBoxes[i].value
  • send this array back to the opening page

  •  
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic