0

How to send enter from javascript to site?

What I real need is to send text to site like filehippo.com in search box, and press enter to search for those text.
So piece of code from site is:

<div id="searchbox">
<form name="f" action="/search">
<input style="color: #999" type="text" id="q" name="q" maxlength="150" value="Search..." onfocus="javascript:clearInputValue('q', 'Search...')" onblur="javascript:setDefaultIfEmpty('q', 'Search...')">
<input type="submit" id="search-submit" value="GO" onclick="javascript:submitQuery('q', 'Search...')">
</form></div>

And my simple code look like this:

javascript: document.getElementById('q').focus();document.getElementById('q').value='Winrar';document.getElementById('f').item(0).click();

And those script just put focus on search box and send text to them, but I need also to do automatically search (send enter), how to do that?

document.getElementById('f').item(0).click(); -> dont work

What I need is to simulate click of mouse, by enter, cause can't send click to element that work properly.

Is it possible to send enter with text?

5
  • Why do you want to simulate click. Does the site use furthermore the bubbled click event, specifically ? Why isn't document.getElementById('f').submit() good? Commented Jul 31, 2012 at 9:29
  • @ I don't know why getelementbyid dont submit as well, i try that on site and that don't work properly. Commented Jul 31, 2012 at 9:33
  • are there multiple items with the same id? ...maybe Commented Jul 31, 2012 at 9:34
  • @ as i can see from in that piece of code no Commented Jul 31, 2012 at 9:37
  • ah, of course, as @David Everlöf noticed, there is no id "f"..ad id to the form Commented Jul 31, 2012 at 9:41

2 Answers 2

3

Use document.f.submit(); to submit the form.

The problem is that there are multiple forms named 'f'

javascript:document.f[0].submit();

So the fully functional line would be:

javascript:document.getElementById('q').value='Winrar';document.f[0].submit();
Sign up to request clarification or add additional context in comments.

8 Comments

i'm not sure this way of accessing an id is valid, at least not in all browsers. Submit is a function, i doubt this works
@StoiaAlex that want to submit i try it
@StoiaAlex How do you exactly put those line in firefox? I use google chrome and put in adressbox javascript:document.getelementbyid("f").submit(); and it don't search.
i'm sorry, I was mistaken, there is no "f" id, if you add id="f" to the form element it should work. But in this resolution the current answer to which we're commenting is valid, it should work.
@DavidEverlöf try it on this site filehippo.com when you put in search box something?
|
0

Use onkeypress attribute of input element.

1 Comment

this have to be automatically the script have to send key without iteration with user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.