/    Sign up×
Community /Pin to ProfileBookmark

Passing js function variables for id (.jsp)

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>
[/CODE]

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:’;
}
}
[/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!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @BlueShadow spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...