One particular webpage contains an ASP.NET button with the following code:
<asp:Button ID="TickButton" runat="server" OnClientClick="SelectSome()" Text="Tick" />
This button is linked to a JavaScript function like this:
function SelectSome() {
var id = document.getElementById("ctl00_ContentPlaceHolder1_txtSelectSome").value;
if (isNaN(id)==false)
{
var frm = document.forms[0], j = 0;
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox" && j < id) {
frm.elements[i].checked = true;
j++;
}
}
}
else
{
alert("You must enter a number.")
}
return false;
}
Surprisingly, when the button is clicked, the JavaScript function executes but then triggers a refresh of the webpage. This behavior goes against expectations as returning FALSE from the function should prevent the refresh as indicated in this useful link: Stop page reload of an ASP.NET button