Reputation: 3539
I have a page in chrome which contains many textboxes and I wish to feed values automatically to them. I already have the list of name-value pairs, so if I could simple execute a series of Javascript commands on the form "document.getElementsByName(NAME)[0].value = VALUE;" I'll be done (I hope...)
So the question is - can I run a JS code "on the spot", or do I have to use a content script somehow?
Upvotes: 37
Views: 114710
Reputation: 24991
You can use bookmarklets if you want run bigger scripts in more convenient way and run them automatically by one click.
Upvotes: 2
Reputation: 21
If you mean you want to execute the function inputted, yes, that is simple:
Use this JS code:
eval(document.getElementById( -- el ID -- ).value);
Upvotes: 1
Reputation: 122906
Right click on the page and choose 'inspect element'. In the screen that opens now (the developer tools), clicking the second icon from the left @ the bottom of it opens a console, where you can type javascript. The console is linked to the current page.
Upvotes: 46
Reputation: 283
Have you tried something like this? Put it in the head for it to work properly.
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(){
//using DOMContentLoaded is good as it relies on the DOM being ready for
//manipulation, rather than the windows being fully loaded. Just like
//how jQuery's $(document).ready() does it.
//loop through your inputs and set their values here
}, false);
</script>
Upvotes: -3
Reputation: 4420
I'm not sure how far it will get you, but you can execute JavaScript one line at a time from the Developer Tool Console.
Upvotes: 5