View textbox maxlength with one click
View textbox maxlength with one click
Submitted by Brent Strange on Mon, 13/03/2006 - 04:53.I love playing around with the DOM and DHTML. I'm old school like that... Don't make fun of me, you recently started poking around with AJAX which makes you no better than me! :)
I find it REALLY cool to be able to manipulate Web pages from the browser URL bar using JavaScript and the DOM. In the past I posted about displaying the site's cookies by simply clicking a Internet Explorer Favorites link that contained JavaScript to display the cookies. Now days, we have cool tools such as the IE Developer Tool Bar, FireFox Web Developer extension, and Site Inspector which all report the same data to you via the same method (DOM and DHTML).
Here at Corillian, we have a test case for every form textbox to check that it has a defined maxlength.. We test for this to help with usability and most importantly to provide the first line of defense in form input. Sometimes something as simple as checking for textbox maxlength is not worth opening a tool and digging through it's data, but on the other hand digging through the HTML can suck too. How often do you find yourself not wanting to do either, but instead count the characters as you type them into the textbox to figure out what that maxlength is? Stop it, stop it, stop it! Stop wasting time! You can do this with JavaScript from the URL bar in the browser. For example, post the Javascript below into the URL bar of your browser and hit the enter key:
javascript:var x=document.getElementsByTagName('input');myVals='';for (var i=0;i<x.length;i++){z=x[i].getAttribute('type');if(z=='text' || z=='password')myVals=myVals+'ID attribute: '+x.item(i).id+'\n'+'Name attribute: '+x.item(i).name+'\n'+'Maxlength: '+x[i].getAttribute('maxlength')+('\n\n')};alert(myVals)
Bam! Nice eh? This script dumps the maxlength for each HTML input tag that has a type attribute equal to text or password to a JavaScript alert. Since some sites use the attribute of name and some use id I dump both to help you figure out what textbox the maxlength applies to.
Add the script above to your Favorites by right clicking this link and
selecting "Add to Favorites" in IE or "Bookmark this link" in FireFox. If you add
it to your Links toolbar (IE) then it's only a click away on each page where you need
to see the maxlength of textboxes. Look at you now, you one click tester! Happy testing.
