Link to home
Start Free TrialLog in
Avatar of error2013
error2013

asked on

JQuery Keypress events not working assistance needed

I am working on a piece of code where I have a html input and on page load I need JQuery to :

1. Focus of the Input (This works)

2. Press the DownKey

3. Press Enter Key

Parts 2 and 3 do not work.

I'm basically trying to get the email history list dropdown to appear automatically but no luck.

Here is the full current code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>


<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

<script type="text/javascript">

 $(document).ready(function(){

$( "#email" ).focus();

$('#email').trigger(jQuery.Event('keypress', {which: 50}));

$('#email').trigger(jQuery.Event('keypress', {which: 13}));
   

 });

</script>


</head>
<body>

 <form>
  Email:<input type="text" id="email" name="email" />
 </form>
 
</body>
</html>

Open in new window

Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

What you are trying to do would require taking control of the user interface, and I think you would have to go into the core browser code to add an interrupt to simulate the events. Even if you managed to do that it would probably trigger the AV to alert that the page contains malicious code.

Cd&
Avatar of error2013
error2013

ASKER

When you go to an email form input on a page you can get a dropdown list of emails that you've used ... I'm just trying to automatically open that .. that's all.

It's for personal use so not trying to get silly code there ... just trying to get that  list to open.
Avatar of Gary
While you can simulate clicks etc on an object you can not emulate those actions
i.e. You can simulate a click on a dropdown but it will not open the dropdown
If doing it automatically saves yoi 10 seconds a day, the total effort to change the behaviour would be such that break even would be somewhere around 10, 000 years, and ther is no guarantee you can actually get it to work right unless you write a custom browsers.  You'll just have to take my word for that.  I have spent some time in those depths and it is not something you want to try unless you are very experienced working at the primitive level.

Cd&
So are you are telling me that it just cannot be done?
Yes
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial