<selectObjectName>.selectedIndex = <newIndex> for your example that would be:
opener.document.formBean.selectElementName.selectedIndex = <newValue>; If your popup has the same <select> element then its easy: opener.document.formBean.selectElementName.selectedIndex = document.popupform.selectElementName.selectedIndex ; If what you have is text that matches a label in the destination try this:
// assign references so we don't have to type x.y.z so much
var text = popup.document.popupform.input.text ;
var oDest = opener.document.formBean.selectElementName ; // iterate through options collection to find matching text attribute
for ( var x = 0 ; x < oDest.options.length ; x++ ) {
if ( text == oDest.options[x].text ) { // I think text.equals(oDest.options[x].text) also
// works, but I was using JS before java so I generally
// write this as ==
oDest.selectedIndex = x ; } }
Warning, I just typed this code in, it may have syntax problems.
Mike Elliott wrote:
I have a situation where the form bean contains objects inside it which represent sets of things which will appear in an <html:select> tag. In particular, the objects have three properties:
selected_ndx ndx_set label_set
One of these objects is the 'moderator' property of the form bean.
The overall design intent was to have an object which could provide the values and labels for an <html:select> statement and have selected_ndx be the value which is changed via the selection process in the web page.
If I write the JSP like this, it works:
<html:select property="moderator.selected_ndx"> <html:options property="moderator.ndx_set" labelProperty="moderator.label_set"/> </html:select>
This generates the following HTML:
<select name="moderator.selected_ndx"><option value="0"></option>
<option value="1">First Selection</option>
<option value="2">Second Selection</option>
<option value="3">Third Selection</option></select>
This successfully displays the selected entity and allows it to be changed via selection through the web page.
However, additionally I need to be able to set the value of this
select from a popup window. That generally means I need to specify
the form element as the target of a javascript assignment. What has
worked in similar circumstances in the past is something like
opener.document.formBean.selectElementName = newValue
where selectElementName is the value of the 'name' attribute from the select element. Here that name is "moderator.selected_ndx". That causes a problem. When the javascript runs (from a popup window) the following javascript error occurs:
Error: opener.document.formBean.moderator has no properties
Which I interpret as the javascript interpreter being able to find the formBean property (which I assume is being furnished by the <html:form> tag) but that there is no attribute of that called "moderator". If I didn't use the dotted notation in the <html:select> tag, the correct attribute gets created, or whatever, and the javascript works OK.
So -- how can I solve this problem? Assuming that the naming is the problem, I've tried introducing a bean like this:
<bean:define id="mod" name="formBean" property="moderator"/> <html:select name="mod" property="selected_ndx">
<html:options name="mod" property="ndx_set" labelName="mod" labelProperty="label_set"/>
</html:select>
Which generates HTML: <select name="selected_ndx"><option value="0"></option> etc.
But that causes the select element to be unselectable; that is, while the getter method (getSelected_ndx()) gets invoked, the setter method (setSelected_ndx()) does not, so that changes to the field no longer get propagated back to the form bean. Even if I could get this to work, I'm dubious that I could have multiple select elements working properly in the same form since they would all have the same name attribute (selected_ndx).
While I'm unconvinced that the failure to invoke the setter method isn't a bug, I still need to solve the problem through some combination of Struts/JavaScript.
Any suggestions?
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]