Hi,
I am having trouble passing the correct id to change the innerHTML.
I have a jsp that display people and their address information. There could be several people in the list, so it is in a loop. That part all works good. There is a drop down list with countries in them. Based on the country they select, I want to change some of the text. Here is what I have:
[CODE]
<tr>
<td class=”datashaded” valign=”top”><font size=”2″><b>Country:</b></font></td>
<td class=”datashaded” valign=”top”>
<select tabindex=”<%=countryTab%>” name=”<%=country%>” size=1″ onChange=”changeText(this.form.<%=country%>, this.form.<%=addressLabel%>, this.form.<%=zipLabel%>);”>
<% for (int i =0; i < countryList.size(); i++ ) {
String countryOption = (String)countryList.get(i);
String countryVal = bene.getAddress().getCountry();
String selected = “”;
if ( countryOption.equalsIgnoreCase( countryVal ) )
selected = “selected”;
%>
<option value=”<%=countryOption %>” <%=selected%> ><%=countryOption%></option>
<% } %>
</select>
</td>
</tr>
<tr>
<td class=”datashaded”><div id=”addr1″><font size=2><b id=”<%=addressLabel%>”>Address:</b></font></div></td>
<td class=”datashaded”>
<input size=20 maxlength=”50″ tabindex=”<%=add1Tab%>” name=”<%=address1%>” value=”<%=address1Value%>” </td>
</tr>
Everytime through the loop, addressLabel has an index added to it so it is unique – so I can refer to each person separately.
Here is the js function:
[CODE]
function changeText(sel, txtField1, txtField2)
{
var selectedValue = sel[sel.selectedIndex].value;
if ( selectedValue == “<%=IParticipantConstants.BENEFICIARY_COUNTRY %>”)
{
document.getElementById(txtField1).innerHTML = ‘Address:’;
document.getElementById(txtField2).innerHTML = ‘Zip:’;
}
else
{
document.getElementById(txtField1).innerHTML = ‘Street or P.O. Box’;
document.getElementById((txtField2).innerHTML = ‘Postal Code:’;
}
}
When I hardcoded the id= value, not matter which group I changed the country on, only the first one was changing, so I knew I needed unique ids for each group. There is more to the table, but this is the good part.
When the onChange fires now, Nothing at all happens.
Can anyone see the problem??
Thanks for looking!