How to fill a search field or email field of a website with javascript?

Hello, guys! I’m newbie in javascript and i would like to make a simple script that inserts a single word in the google’s search field. To start, i made a simple html page as you can see below.

<html>
<head>
<title>Page 2</title>
</head>
<body>

<form name="robgeek">
	Username: <input type="text" name="username"/>
	Password: <input type="password" name="password"/>
	<input type="submit" value="Submit!">
</form>

<script type="text/javascript">

	//Here i can access the robgeek form and manipulate "username", "password" and "submit".
	document.write(document.robgeek.username.name);

</script>
</body>
</html>

Considering this simple webpage as if were google: How can i make a javascript to access those fields, like “Username” and “Password”? I believe i could do the same thing with Google or really make a javascript to access for me my email.
I know how to get access in those fields but only in the same code, like you can see above. But i don’t know how to get access and fill those field with a script only for this task. The following code is what i did. I considered the webpage above as a website, and i tried to get access with my following javascript. But i don’t know what to do now!
Could you guys help me?

<html>
<head>
</head>
<body>

	<a href="#" onclick="window.open('file:///home/rob/index2.html');">Link here!</a>

<script type="text/javascript">
	//I don't know what to put here!
</script>

</body>
</html>

Thank you!

Welcome to Sitepoint Rob!

Not much of a javascript Guru myself, though have you tried the HTML5 placeholder?

Username: <input type="text" name="username" placeholder="Enter username" />

cb

i would like to make a simple script that inserts a single word in the google’s search field…Considering this simple webpage as if were google: How can i make a javascript to access those fields

I’m really confused here…do you want a script to insert words into google’s search field, a script that accesses usernames & passwords, or a script that creates new users with passwords? And, why?

Look, for example, a friend of mine are using a javascript to download all images from a website. I would like to do similar things, not exactly the same thing, but similar things and i have to start for somewhere, right?

First thing to do, once i already have the basic knowledge about javascript is learn how to communicate with a website and access his code using javascript. After that i believe i need to learn how to identify objects in this code, something like “getElementById”, i believe. An finally learn how to interact with this object.

I forgot to say one thing.
And i would like to start with that example about google. I would like to fill the search field with a simple word. Communicate with google, identify the search field in the code and put a word there. I don’t even need send a request to server, just put a simple word there. To start, for me, it’s enough.

I know how to identify a element and interact with him only if my javascript is with html code, like i did in my first example. What i don’t know is how to do the same thing with other website.

You cannot use JavaScript to interact with someone else’s website in this way. Sorry.

If it is your page, it would be a piece of cake to use JS to populate a search field, but the security implications of being able to use JS to inject arbitrary code into a third party page are immense.

I suggest you read something like Jump Start JavaScript to get a handle on the basics.

Hello! I’m using Web Console in Firefox to run some Javascript commands and, in Google website, i would like to know how click the Google Search button using Javascript?

To fill the Search Box i use the following command in Web Console.

document.getElementById('gbqfq').value='Hello World!';

Now, i want to click on the Search Button, but i don’t know how to do it!

Thank you!

As Pullo said, javascript is not intended for playing with other people’s sites. If it were, there wouldn’t be sites to visit because people would be changing the code, content, etc.

If you want to access google’s services, though, you will need to use its API:

if you want to learn more javascript, you can go to http://www.htmlgoodies.com , http://www.w3schools.com , or anywhere else where they have tutorials (google/bing javascript tutorials)

Hi
If that search box is into a <form> with id=“some_id”, try ad submit() to that form.

docment.getElementById('some_id').submit();