Fill every field on page with a string using a bookmarklet

173 views Asked by At

I'm testing for text input fields that have issues with various characters, and I have no idea where to start, but I want a bookmarklet that fills every form on the page with

 ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿƒΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϑϒϖ•…′″‾⁄℘ℑℜ™ℵ←↑→↓↔↵⇐⇑⇒⇓⇔∀∂∃∅∇∈∉∋∏∑−∗√∝∞∠∧∨∩∪∫∴∼≅≈≠≡≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈⌉⌊⌋〈〉◊♠♣♥♦"&<>ŒœŠšŸˆ˜‌‍‎‏–—‘’‚“”„†‡‰‹›€

can anyone help?

1

There are 1 answers

0
GitaarLAB On

Bookmarklet using querySelectorAll for modern browsers (replace 'my_test_string' with the (optionally escaped) teststring you require):

javascript:(function(s){for(var n=document.querySelectorAll('input[type=text]'), L=n.length; L--; n[L].value=s);})('my_test_string');

Note that you can pass in multiple CSS selectors:

javascript:(function(s){for(var n=document.querySelectorAll('input[type=text], input[type=hidden], textarea'), L=n.length; L--; n[L].value=s);})('my_test_string');

Alternative fallback for legacy browsers (using getElementsByTagName in conjunction with a short-circuit type test for 'text'):

javascript:(function(s){for(var n=document.getElementsByTagName('input'), L=n.length; L--; n[L].type.toLowerCase()==='text' && (n[L].value=s));})('my_test_string');

Pure javascript, no libraries required!

Hope this gets you started!

PS: Yes, it's 'golfed': it's a bookmarklet (and we need to leave as much room as possible for the (optionally escaped) test-string).. besides the routine is as basic as it can get.. note that the semicolon closing the packed for-loop is required!