2

How simulate Enter Key Hit using with both javascript & jquery?
I know js has been deprecated but I need it.
I found many threads about simulate KeyPress EVENT, but I am talking about simulate enter key press just like a human do using with js & jquery.
how can I do that?
this is my textBox and I want to hit enter on it by codes :

var texts = document.getElementsByTagName("textarea");
for (var i = 0 ; i < texts.length ; i++)
{
  if (texts[i].getAttribute("id") == "my_goal_textBox")
  {
    alert("hi");
    texts[i].value = "hello";
    //->Now here i want to hit enter key programatically, how?  
 }
}  
BenMorel
  • 34,448
  • 50
  • 182
  • 322
SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent – Derek 朕會功夫 Jan 22 '14 at 05:23
  • @Satpal, yes. enter on textbox. – SilverLight Jan 22 '14 at 05:24
  • You can do `texts[i].value += "\r\n";` – Satpal Jan 22 '14 at 05:24
  • @Satpal : no. i need to simulate enter key press, just like a human press that key by his/her hand... – SilverLight Jan 22 '14 at 05:27
  • @Moonlight—you can [dispatch a keypress event](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.dispatchEvent) with appropriate parameters from a particular target element, however browsers may not treat it exactly like user input. You can't fool them, they *know* where the event came from. See also [Creating and triggering events](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events). – RobG Jan 22 '14 at 05:30

0 Answers0