/    Sign up×
Community /Pin to ProfileBookmark

JAVASCRIPT BUG onchange

Hi all,

I’m new in this forum, but i want to know if anyone could help me resolve this problem!
Um using DOM and javascript to create dinamically comboboxes. I also have a function associated with each comboboxe that runs when there is an update of the value. For each comboboxe onchange function it is passed a diferent value, but all the functions receive the same value!

HTML file:

[FONT=Courier New]<HTML>
<HEAD>
<script language=”JavaScript” type=”text/javascript” src=”bug.js”></script>
</HEAD>
<BODY onload=’bug(“tabelaID”);’>
<table ID=”tabelaID”>
<tbody>
</tbody>
</table>
</BODY>
</HTML>[/FONT]

bug.js:

[FONT=Courier New]function bug(id) {
var tabelaid = document.getElementById(id).getElementsByTagName(“TBODY”)[0];
for (var x=0; x < 3; x++) {
linha_principal = tabelaid.insertRow(x);
coluna_principal = document.createElement(“TD”);
tabela = document.createElement(“TABLE”);
tabela.id = “tabela_“+x;
tbody = document.createElement(“TBODY”);
linha1 = document.createElement(“TR”);
celula6 = document.createElement(“TD”);
valor7 = document.createElement(“A”);
valor7.innerHTML = x+”—–“;
celula6.appendChild(valor7);
valor6 = document.createElement(“SELECT”);
valor6.onchange = function () { alert(x); };
valor6.name = “berco_
“+x;
valor6.id = “berco_”+x;
valor6_1 = document.createElement(“OPTION”);
valor6_1.value = “0”;
valor6_1.innerHTML = “NÃO”;
valor6.appendChild(valor6_1);
valor6_2 = document.createElement(“OPTION”);
valor6_2.value = “1”;
valor6_2.innerHTML = “SIM”;
valor6.appendChild(valor6_2);
celula6.appendChild(valor6);
linha1.appendChild(celula6);
tbody.appendChild(linha1);
tabela.appendChild(tbody);
coluna_principal.appendChild(tabela);
linha_principal.appendChild(coluna_principal);
}
}[/FONT]

Can anyone help me?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangAug 25.2005 — Do it after the object is attached:
function BindEvent(el) {
if (el.addEventListener) {
el.addEventListener('change', function() {alert(x);}); // Mozilla
}
else {
el.attachEvent('onchange', function() {alert(x);}); // IE
}
}
×

Success!

Help @Tiago 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.28,
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,
)...