macleodjb
01-17-2009, 06:30 PM
Hi guys i have this script to add a textbox at runtime. I wanted to limit the number of textboxes the user could throw out so i added a counter and limit to the script. Only now it doesn't work. Any suggestions why?
Here's the code
var counter = 1;
var limit = 3;
function addEvent() {
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
} else {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "skill"+num;
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<input type='text' name='myInputs[]'><a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\">Remove</a>";
ni.appendChild(newdiv);
counter++;
}
}
Here's the code
var counter = 1;
var limit = 3;
function addEvent() {
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
} else {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "skill"+num;
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<input type='text' name='myInputs[]'><a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\">Remove</a>";
ni.appendChild(newdiv);
counter++;
}
}