Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

onFocus highlights all data in textbox

Posted on 2003-03-26
6
Medium Priority
?
757 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:astro26
  • 3
  • 2
6 Comments
 

Expert Comment

by:havik83rs
ID: 8213322
You could use this:

  // 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)"/><br />

It clears the text automatically for the user.

Havik
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8213465
<INPUT type="text" id=text1 name=text1 onFocus="(this.select())" >


Fritz the Blank
0
 

Author Comment

by:astro26
ID: 8213653
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 200 total points
ID: 8213820
Wel, even if they click on the field with a mouse, it still fires this code. Try it.

Fritz the Blank
0
 

Author Comment

by:astro26
ID: 8213982
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.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8214045
Glad to have helped,

Fritz the Blank
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question