Fire click event on Enter key

Hi, can someone help me in triggering click event programmatically? I could invoke the submit details by calling function on enter key, but the cursor from the text field doesn’t disappear after pressing the Enter button.I tried focusing the button.But nothing works.Did someone tried focusing the button? or link the Enter key to fire button click event programmatically?

Hi

not sure what you finally need, please clarify your question (describe step-by-step logic or desired behaviour)

but if you have (1):

myForm.attachEvent("onButtonClick", function(){...})

then you can (2):

myForm.callEvent("onButtonClick", [name]);

when name - button name, and code (1) will called

I have userid and password text boxes.A simple login button of type button. These are declared in dhtmlxForm.I have to Login on pressing Enter key after entering the password or by clicking Login button.I am trying various ways to get that task work.They are

  1. I am trying to fire Onclick event when the “enter” key is pressed in password textbox.
    code: myForm.getInput(“txtPassword”).onkeyup = function (event) {
    if (event.keyCode == 13) {

     document.getElementById("buttonname").click();
       }
    

myForm.attachEvent(“onButtonClick”, function (name, command) {
getLoginDetails();
});
document.getelementbyid[‘buttonname’].click doesnot work.
2)tried myform.attachevent(“onenter”,function()){}.
figured that i need javascript code of the “onEnter” event.
Can you provide the code? so that i can use Onenter event in my view page.

Is there any other best way to get that done.since, both click event and “enter” key execute same function.Hope you understood the problem I am facing.Let me know if you need more details.

Hi

[code]var myForm = new dhtmlXForm(“parentId”, [
{type: “input”, name: “login”, …},
{type: “password”, name: “pwd”, …},
{type: “button”, name: “do_login”, …}
]);

// handle button click
myForm.attachEvent(“onButtonClick”, function(name){
// one event for several buttons,
// if more than one button you need extra check
if (name == “do_login”) do_login();
});

// handle enter key
myForm.attachEvent(“onEnter”, function(){
// custom logic if any
do_login();
});

// main login function
function do_login() {
// your lohin code
}[/code]

Hey,
Thanks for the reply.The myform.attachevent(“onenter”,function()) doesnot work for me.I tried putting alert(“enter pressed”) in it.It doesn’t work. my form.js doesnt have prototype/javascript code.I Think,that’s the reason its not working.Could you help me with it?

Thanks in advance!!

Hi

please send your completed demo including all corresponding js/css files to support@dhtmlx.com, direct link also an option

Hi,
I have attached the demo.Have a look and let me know why “onEnter” event doesn’t work for me.I tried alert(“enter triggered”).It doesn’t work.Can we create function which would fire the Onbuttonclick event programmitically.e.g Hit Enter after entering password and “onbuttonClick” should get triggered.
MyDemo.zip (78.6 KB)