Call backend function from javascript?

Hi, when a user presses enter on this button I want it to trigger "saveitem_Click". I understand that this is the normal behavior, but I have a table onkeydown function redirecting enters in to tabs document wide, so I need to reenable that for just this field.

Here is the button:

<td onkeydown = "javascript:press_save()" style="height: 14px;">
                    <asp:Button ID="saveitem" runat="server" TabIndex="23" Text="Save" Width="46px" OnClick="saveitem_Click"


Here is the javascript function. Both commands I tried give an error.

 function press_save()
        {
                document.forms[0].saveitem.onclick();
                saveitem.click();
                 
        }


Thanks!


Terry
TerryBurgerAsked:
Who is Participating?
 
nabsolCommented:
Hi

Is your button in a form.

document.forms[0].saveitem.onclick();
or
document.forms[0].saveitem.click();

should work.

By Nab
0
 
deepaknetCommented:
You can use AJAX to do this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.