G
garey
Hello -
I have the following function
function write_hdcp_select() {
var myDiv = document.getElementById("myDiv");
myDiv.innerHTML = "";
var title = document.createElement("h3");
title.appendChild(document.createTextNode("Select the number"));
myDiv.appendChild(title);
for(var i = 0;i < 10;i++) {
var nh = i;
var loc = "http://localhost/cgi-bin/myCgi.cgi?num_args=" + nh;
var but = document.createElement("button");
but.appendChild(document.createTextNode(nh));
but.onclick = function() {
window.location = loc; };
myDiv.appendChild(but);
}
}
The idea of the function is to generate a set of buttons, and when any
of the buttons is clicked, it calls a cgi with a numeric argument.
Debugging, I can see that loc contains the correct value before each
onclick assignment, and the buttons show up with the correct number
displayed. But every button's onclick handler ends up with the highest
numeric value as the argument to the CGI script. What's going on?
Any help appreciated;
Garey Mills
I have the following function
function write_hdcp_select() {
var myDiv = document.getElementById("myDiv");
myDiv.innerHTML = "";
var title = document.createElement("h3");
title.appendChild(document.createTextNode("Select the number"));
myDiv.appendChild(title);
for(var i = 0;i < 10;i++) {
var nh = i;
var loc = "http://localhost/cgi-bin/myCgi.cgi?num_args=" + nh;
var but = document.createElement("button");
but.appendChild(document.createTextNode(nh));
but.onclick = function() {
window.location = loc; };
myDiv.appendChild(but);
}
}
The idea of the function is to generate a set of buttons, and when any
of the buttons is clicked, it calls a cgi with a numeric argument.
Debugging, I can see that loc contains the correct value before each
onclick assignment, and the buttons show up with the correct number
displayed. But every button's onclick handler ends up with the highest
numeric value as the argument to the CGI script. What's going on?
Any help appreciated;
Garey Mills