How do I call this javascript function on this ASP.net webform on a button click? I added the .js file in the application but for some reason the button is not being able to refer to the .js file. I am getting a Javascript runtime error saying: divName is undefined. What am I doing wrong? Any kind of help would be appreciated. Thanks!
Javascript code (The file is check.js):
var counter = 1;
var limit = 20;
function addInput(divName) {
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
} else {
var newdiv = document.createElement('div');
newdiv.innerHTML =
"Dimension Type " +
"<br><input type='text' name='myInputs[]'>" + "Dimension " +
"<br><input type='text' name='myInputs[]'>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
return true;
}
The ASP.Net button code:
<p class="auto-style9">
<script src="check.js" type="text/javascript"></script>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" OnClientClick="return addInput(divName);" />
</p>
<p class="auto-style9">