Buttons OnClick Event not firing when it causes a textboxes onChange event to fire first

房东的猫 提交于 2019-12-14 04:04:33

问题


I have a few textboxes and button to save their values on a webpage. The onchange event of the textboxes fires some js which adds the changed text to a js array. The ok button when clicked flushes this to the database via a webservice. This works fine except when the onchange event is caused by clicking the ok button. In this scenario the onchange of the textboxes still fires but the onClick event of the button does not. Any ideas?

textboxes look something like

<input name="ctrlJPView$tbcTabContainer$Details$JP_Details_Address2Text" type="text" value="test" 
id="ctrlJPView_tbcTabContainer_Details_JP_Details_Address2Text" onchange="addSaveDetails('Jobs###' +    document.getElementById('ctrlJPView_tbcTabContainer_Details_JP_Details_Address2Text').value + ');" style="font-size:8pt;Left:110px;Top:29px;Width:420px;Height:13px;Position:absolute;" />

My save button

<input type="button" name="ctrlJPView$btnOk" value="OK" onclick="saveAmendments();refreshJobGrids();return false;__doPostBack('ctrlJPView$btnOk','')" id="ctrlJPView_btnOk" class="ControlText" style="width:60px;" />

UPDATE: I guess this comes down to one of two things. 1) Something is happening before the onClick of the button gets called to surpress that call such as an inadvertent return false; or 2) the onClick event isn't firing at all. Now I've rem'd out everything actually inside the functions that are being called beforehand but the problem persists. But if i remove the call altogether it works (???)


回答1:


is the __doPostBack function the one failing to execute? in this case, the return false is the obvious problem - once you return, no more code gets executed.

on a more pedantic note, you should really stop using onBlah handlers in your html, and instead use a modern javascript library that provides event observers. i recommend jquery but extjs or prototype would also work and make life much easier for you in a thousand other ways.



来源:https://stackoverflow.com/questions/1503350/buttons-onclick-event-not-firing-when-it-causes-a-textboxes-onchange-event-to-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!