I am trying to create a click event within a function, which doesn’t seem to work.
Here is my code:
<input class="text2" type="text" name="" id="text1">
<input size="20" id="high_light" type="button" />
<span><a href="#" id="add"> + Add more</a></span>
var count = $('.text2').val();
var divCount = count;
window.onload = function(){
document.getElementById("add").onclick = function(){
if(divCount < count){
divCount++;
var input = document.getElementById("high_light" + divCount);
input.parentNode.style.display = "";
}
};
}
Basically, I just want to add more buttons with 1 click. The text2 class in where I will enter the value of how many buttons I want to add. When I change the value of divCount to 1 (divCount = 1), it is working but it is just a fixed adding of button. I am new to this so i apologize if my code in not that organized.
This code is working, but it is only adding buttons 1 by 1 with a max of 4.
window.onload = function(){
document.getElementById("add").onclick = function(){
if(divCount < 4)
{
divCount++;
var input = document.getElementById("high_light" + divCount);
input.parentNode.style.display = "";
}
};
}
divCountis equal tocount, so yourifstatement will never run