aspose file tools*
The moose likes Struts and the fly likes set text filed values based on drop down selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "set text filed values based on drop down selection" Watch "set text filed values based on drop down selection" New topic
Author

set text filed values based on drop down selection

Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
Hi ranchers,

I have a drop down with two values : 'nos.' and 'kg' and i have 10 text fields.

By default the value of the text field is 'nos.' .
If i select 'kg' in the drop down all the text fields should change to kg.

Here is my code:

<td>
<html:select property="UOM" onchange="changeValue(this.value);">
<htmlption value="nos."></htmlption>
<htmlption value="kg"></htmlption>
</html:select>
</td>

<logic:iterate id="lines" name="purchaseOrderBeanForm" property="lines">
<tr>
<td><%=i %></td>
<td align="center"><html:text indexed="true" name="lines" property="POD"/></td>
<td align="center"><html:text indexed="true" name="lines" property="PON"/></td>
<td><html:text indexed="true" name="lines" property="POQ" size="6"/></td>
<td></td>
<td><html:text indexed="true" name="lines" property="UOM1" size="4" value="nos."/></td>
</tr>
<% i++; %>
</logic:iterate>

I am using DynaActionForm.

the entry in struts-config is as follows:
<form-bean name="purchaseOrderBeanForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="lines" type="ActionForm.AddPOBean[]" size="10" />
<form-property name="selected" type="java.lang.String" />
<form-property name="arrCustID" type="java.util.ArrayList" />
<form-property name="UOM" type="java.lang.String" />
<form-property name="POB2B" type="java.lang.String" />
<form-property name="POTX" type="java.lang.String" />
<form-property name="PONO" type="java.lang.String" />
</form-bean>

This is what i tried:
function changeValue(value)
{
var weight = value;
var i = 0;
alert(weight);
alert(document.purchaseOrderBeanForm.lines[0].UOM1.value);
document.purchaseOrderBeanForm.lines[1].UOM1.value = "kg";

}

Please help me out!!!

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Really, it's a JavaScript question.

You neglect to actually mention *what* doesn't work, just saying "it doesn't work" is not helpful: TellTheDetails.

That said, if you're trying to change 10 text fields, it'd make sense to have the JavaScript change 10 text fields--yours changes only a single text field, which is around 9 short. Perhaps a loop, or in any reasonable JavaScript library, a selector with a function.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: set text filed values based on drop down selection