tags:

views:

268

answers:

1

What does "Return false;" in onclick event for JavaScript mean?

    <input 
      type="button" 
      runat="server" 
      id="btnCancel" 
      value=" Cancel " 
      style="width:70px;"
      onclick="document.location.href = 'ReportPanel.aspx'; return false;" 
    />

in the onclick event. It has return false; What does it mean? What does it mean if return true;?

+10  A: 

It says "the event never happened" to the browser. If you had a submit button instead of a simple button and didn't have "return false", the form would get submitted when you click it (after executing the javascript).

naivists
Right - without it the click would still be processed and the browser will navigate away or perform the form submit action.
Eilon
It is the same as to set the server control properties as PostbackEnabled="false" in asp.net ,right?
Ybbest
Actually, no ;-) Enabling postback on the server side introduces specific javascript code to your html. So, your simple HTML select becomes <select onchange="callPostback()"> where the callPostback() explicitly submits the form back to itself.
naivists
Cool thanks :) :)
Ybbest