0

I have a simpe jQuery autocomplete input box with the ID 'medID'

$('#medID').val("Par").focus().keydown();

I use the code above to put a value in the box, trigger focus and then key down to search.

It returns between 1-5 values.

How do i get it automaticly select one of the suggested values?

I have tried:

$('#medID').children()[0].focus().click();

and

$('#medID').children().focus().click();

But the suggested auto complete values are direct chilren of the input box?

This is so i can test this part of my system without the need of a user.

Lemex
  • 3,772
  • 14
  • 53
  • 87

2 Answers2

1

I'm not 100% certain, but I think browsers prohibit this. Your request might turn out to be impossible.

If it were possible, a malicious script could gain access to data that users had previously typed into input fields, e.g. credit card numbers or email addresses, using a script just like the one you outlined. This would be a pretty bad security hole.

Sorry about that. Perhaps you could get away with just looping through the input values your want to test and calling $('#medID').val(testValueHere) instead?

Dan Fox
  • 1,643
  • 15
  • 10
0

The jQuery UI team do something similar for their own unit tests for autocomplete. See this answer for more details.

Community
  • 1
  • 1
Rune Vejen Petersen
  • 3,201
  • 2
  • 30
  • 46