File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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:

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

<logic:iterate id="lines" name="purchaseOrderBeanForm" property="lines">
<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><html:text indexed="true" name="lines" property="UOM1" size="4" value="nos."/></td>
<% i++; %>

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" />

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


Please help me out!!!

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

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

[Asking smart questions] [About Bear] [Books by Bear]
David Newton

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:
subject: set text filed values based on drop down selection
It's not a secret anymore!