/    Sign up×
Community /Pin to ProfileBookmark

getElementsByName and innerHTML

onload I call a function to change a 1, 2, or 3 to text based on that number. The divs with this name are created dynamically in a gridview so I have to use getElementsByName which I haven’t used up until this point but it seems easy enough.

I’m getting no errors in my firefox error console but my innerHTML is not changing. Does someone see the issue in this code?

*SOLVED* I probably should have noticed that I failed to add .innerHTML to the comparisons so I was comparing objects to numbers on accident

[code] <script type=”text/javascript” language=”javascript”>
function changeAction() {
var array1 = document.getElementsByName(“actionID”);
var count = array1.length;
window.alert(count);
for (var i = 0; i < count; i++) {
if (document.getElementsByName(“actionID”).item(i) == 1) {
document.getElementsByName(“actionID”).item(i).innerHTML = “Payment”;
} else if (document.getElementsByName(“actionID”).item(i) == 2) {
document.getElementsByName(“actionID”).item(i).innerHTML = “Auto Refund”;
} else if (document.getElementsByName(“actionID”).item(i) == 3) {
document.getElementsByName(“actionID”).item(i).innerHTML = “Admin Refund”;
}
}

}
</script>[/code]

*EDIT*
Oh yea, that window.alert is displaying the proper amount of elements found too.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@OfekmeisterSep 02.2010 — Show more code please.
×

Success!

Help @eTech1 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.18,
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,
)...