javascript - OnClientClick causes webpage refresh -


i have asp.net button on webpage:

<asp:button id="tickbutton" runat="server" onclientclick="selectsome()"  text="tick" /> 

and javascript function:

 function selectsome() {         var id = document.getelementbyid("ctl00_contentplaceholder1_txtselectsome").value;         if (isnan(id)==false)         {             var frm = document.forms[0], j = 0;             (i = 0; < frm.elements.length; i++) {                 if (frm.elements[i].type == "checkbox" && j < id) {                     frm.elements[i].checked = true;                     j++;                 }             }         }         else         {             alert("you must enter number.")         }         return false;     }   

when click on button; javascript function runs , webpage refreshes. why webpage refresh? according link; returning false should stop webpage refreshing: stop page reload of asp.net button

use return clientclick.

<asp:button id="tickbutton" runat="server" onclientclick="return selectsome()"  text="tick" /> 

or can use html button of server side coding not required then.

<asp:button text="tick" runat="server" onclientclick="return selectsome()" /> 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -