views:

44

answers:

3

let's assume there is a site http:/ /testsite.com, with some filds and submit button.

Is there a way, to write a javascript script, which will fill all filds with values i want, and make submit operation automaticaly?

Is it possible, maybe there is some documentation about it?

Thanks

UPDATE

i don't have access to the script of site, i must make it from another server.

+1  A: 

Sure, try this:

$('form').filter('input').each(function() {
   $(this).val('Some value');
}).end().submit();
Jacob Relkin
+1 simple and elegant :)
Sarfraz
i don't have access to their script. i must do it from my webserver.
Syom
+2  A: 

Do you mean a site that is not your own? Like, you want to embed another site's form into your webpage and then auto-fill some values? No, generally speaking this cannot be done because of the same-origin policy. The best you could do is proxy for that site, e.g. your web server can fetch the form, fill out values and present that to your users. This won't work (or, not very well) if the other site requires authentication.

Jesse Dhillon
+1  A: 

Maybe you're looking for something like Selenium, which can record your actions (using a browser plugin), save them as test scripts, and replay them later.

Another option would be to craft a custom POST request using CURL, or create your own form that submits to the page that handles the form on testsite.com.

It really depends on what you're trying to accomplish.

grossvogel
Selenium seems very useful thing:) it make what i need.and what about, if i get all html of the site, usind `php file_get_gontents() function`, and then make the request. seems it will work?
Syom
`file_get_contents` will make a GET request by default, but you can feed it a context to change this to POST and supply the necessary form data. See the manual for `stream_context_create`: http://php.net/manual/en/function.stream-context-create.php
grossvogel
Umm... Selenium can't access or script input into cross-site IFrames.
Jesse Dhillon
OP didn't say anything about frames.
grossvogel
How else do you propose to get cross-domain content into a document that you have scripting authority over? Selenium sits in `/selenium` (or similar) of your document root.
Jesse Dhillon
It's hard to tell whether the question is from a website author who wants his site to interact with another, or just a user who wants an automated way to submit a form on a random website. Being unsure, I threw in a little for each. I hope that's OK with you.
grossvogel
He said in the question "i don't have access to the script of site, i must make it from another server."
Jesse Dhillon
Clearly we're both doing a little guessing as to what's OP is really up to. I'm really sorry you don't like my interpretation of the question.
grossvogel
It just doesn't seem like you considered the obvious case. I don't understand what interpretation of the question would allow for Selenium to be a sensible answer, except for one which ignores the information provided.
Jesse Dhillon
The second part of my answer shows that I did consider that case. You're just giving me hell for ALSO considering another case, and it's truly tiresome.
grossvogel
Beg your pardon, sir, if I question for a moment whether or not your answer actually solves anything.
Jesse Dhillon