views:

517

answers:

2

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 (???)

A: 

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.

Igor
The __doPostBack is being appended because in my .net code i've set the inputs' useSubmitBehavior to false. The function which looks after the saving is the saveAmendments function which should have excuted before return false. You would think that possible something is failing in the textboxes onchange event but from debugging it doesn't appear so. I've scaled back to function todo nothing essentially.
A: 

I have the same issue,

I have created a simple web form, containing one text box and one button. I have captured the onblur event of the text box.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
    function onTextBoxBlur()
    {
        alert("On blur");
        return true;
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server" onblur="onTextBoxBlur();"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>

When I click on the button then, the onblur event of textbox occurs but the onclick of the button doesn't. And when I remove the alert box from the js function then it works fine. I think it is due to the alert box. Any idea why is this so?

EDIT :

Please refer my post, http://stackoverflow.com/questions/3245350/button-click-event-lost-due-to-the-alert-box-in-text-box-onblur-event

Vinod T. Patil