Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

set text filed values based on drop down selection

 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic