JavaScript / jQuery setting a content to <div> not sticking after postback -


this code:

<asp:button id="btnsave" runat="server" onclick="save" cssclass="stylizedbutton" resourcekey="btnsave" />     <div id="lbltot"></div> 

javascript code:

$(document).ready(function() {               $("#<%= btnsave.clientid %>").click(function() {                   var functionreturn = true;                   var focuselement = null;                   var tot = $("<%= lbltotal.clientid %>").val();                   var txt1 = $("<%= txt1.clientid %>").val();                   var txt2 = $("<%= txt2.clientid %>").val();                   var txt3 = $("<%= txt3.clientid %>").val();                   var txt4 = $("<%= txt4.clientid %>").val();                   var cal = parseint(txt1) + parseint(txt2) + parseint(txt3) + parseint(txt4);                   if (cal == 100)                   { return true; }                   else {                       $("lbltot").html("total must equal 100%");                 focuselement = tot;                functionreturn = false;                }           });       }); 

on client side validation, have check value of textbox, , total should equal 100. if true, should allow execute. if not, need throw error stating total should 100.

what happens that, after triggering submit button, show text message until postback, , disappears. part:

else {                           $("lbltot").html("total must equal 100%");                     focuselement = tot;                    functionreturn = false; } 

is there better way display error persist?

you should return functionreturn submit action won't happen


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -