New to this forum so I'm sorry if this is the wrong forum or if this is too simple of a question.
I would like that if I navigate to an input item type=text that the text in that item will be automatically selected (highlighted). Is there a way to do this on the input item without creating a class and assigning that class to each item?
Does the field already have text in it that you want highlighted or are you talking about the text the user inputs? Or are you referring to highlighting the text when a user wants to copy and paste it?
welcome aboard mlarch, the straight answer - when you need to select certain portions of text, this is one of the "effects" that normally requires different handling for different browsers. For the whole value of the field, the select method might work for you.
edit: oops, missed this:
I would like it to work like onFocus="this.select" but I would like to do it form-wide instead of putting onFocus on each item.
OK, well the best approach then is to attach the behaviors externally Given
<form method="post" id="myform" action=""> .....
You could do something like this (tested:)
A note on what's happening: Browsers render top-down, so code in the head directed at page elements won't find them because they haven't rendered yet:
Normally you'd just put the code at the bottom of the page, but window.onload allows you to make it portable, put the code anywhere you want. window.onload delays execution of the code until the page has fully loaded.
On load it executes the function attachBehaviors, which loops through the form elements of the form id "myform" and if they are text or textarea type elements (obviously won't work on select lists) it assigns the behavior to the current element in the loop using the this keyword.
This keeps your page output lean and mean, not clogged up with code, if you want to take it a step further you put the JS in an external file and put this in the head: