astro26
asked on
onFocus highlights all data in textbox
I have a form which users must enter currency. I have default values of 0.00, how can I highlight the entire '0.00' so that if a user enters 7, the value in the textbox is 7 and not 70.00 (7 prepended to 0.00)
<input type="text" name="total" value='0.00' /><br />
<input type="text" name="total2" value='10.00' /><br />
<input type="text" name="total3" value='5.00' /><br />
<input type="text" name="total4" value='12.00' /><br />
Question
When the user enters the textbox (if enabled) via mouse or tab keypress, how can I let the user just enter '7', instead of deleting "0.00", then entering "7".
in otherwords, can I highlight the value in the textbox in an "onfocus???" or similar event.
TIA
<input type="text" name="total" value='0.00' /><br />
<input type="text" name="total2" value='10.00' /><br />
<input type="text" name="total3" value='5.00' /><br />
<input type="text" name="total4" value='12.00' /><br />
Question
When the user enters the textbox (if enabled) via mouse or tab keypress, how can I let the user just enter '7', instead of deleting "0.00", then entering "7".
in otherwords, can I highlight the value in the textbox in an "onfocus???" or similar event.
TIA
<INPUT type="text" id=text1 name=text1 onFocus="(this.select())" >
Fritz the Blank
Fritz the Blank
ASKER
Thanks for the responses!
havik83rs was close, but I do not want to clear the box, incase the user is just tabbing through the form and making no changes.
Fritz, this works great for tab.
If I was using a mouse, would I use onmouseup? if so, how would the user select 1 digit they wanted to change. are the mouse events good to use?
TIA
havik83rs was close, but I do not want to clear the box, incase the user is just tabbing through the form and making no changes.
Fritz, this works great for tab.
If I was using a mouse, would I use onmouseup? if so, how would the user select 1 digit they wanted to change. are the mouse events good to use?
TIA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great Answer, the mouse event didn't fire for me at first, but I copied it exactly as above and it works.
thanks for bearing with me, and thanks for the lightning fast response.
thanks for bearing with me, and thanks for the lightning fast response.
Glad to have helped,
Fritz the Blank
Fritz the Blank
// This function clears text away when the textfield is focused
function clearText(field) {
if(field.defaultValue == field.value)
field.value = ""
}
<input type="text" name="total" value='0.00' onfocus="clearText(this)"/
It clears the text automatically for the user.
Havik