开发者

help me understand JS execution on onclick event of button

<input type="button" name="reset"
       onclick="return ValidateValue(); __doPostBack('ApplyBtn','')" />

The above is the code generated for asp server button button control on browser.

Now my query is that irrespective of ValidateValue() returning true/false __doPostBack('ApplyBtn','') function is not showing any effect for me.

My understanding is that string passed to onclick acts like function body, and return will from first function will return control preventing second function from exec开发者_开发百科ution. Is that correct ?

Please provide helpful inputs.


Your understanding is correct...and it's easily fixed :), instead of this:

return ValidateValue();

Do this:

if(!ValidateValue()) return false;

This way you only abort early if there is a reason to abort, otherwise you continue executing the rest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜