By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,528 Members | 969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,528 IT Pros & Developers. It's quick & easy.

Clear value in a text box using onClick

P: 1
i want to be able to clear the value in the text box as soon as I click on it. I thought the code may be something like this:

onClick="(this.value='')"

Any Suggestions?
May 24 '07 #1
Share this Question
Share on Google+
4 Replies

10K+
P: 13,262
i want to be able to clear the value in the text box as soon as I click on it. I thought the code may be something like this:

onClick="(this.value='')"

Any Suggestions?
Moved to Javascript forum
May 25 '07 #2

P: 5
If u want to clear all the text box and change other controls to inital mode then u can simply have your controls inside a form and then use the following code
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. fromreset()
  3. {
  4. myform.reset(); //will reset all the controls in ur page to initial stage.
  5. (or) 
  6. document.myform.[textbox Id] = " "; // will clear the textbox alone
  7. }
  8.  
  9. <form name="myform" id="myform">
  10. your code
  11. may be you have some button ... on that button's onclick option
  12. onclick = "javascript:formreset();">
  13. </form>
  14.  
May 25 '07 #3

gits
Expert Mod 5K+
P: 5,390
i want to be able to clear the value in the text box as soon as I click on it. I thought the code may be something like this:

onClick="(this.value='')"

Any Suggestions?
... what's wrong with it? the following example works just fine (actually tested in IE, MOZ, FF):

Expand|Select|Wrap|Line Numbers
  1. <input type="text" id="tx" name="tx" value="click" onclick="this.value='';"/>
  2.  
post some lines of code where an error occurs

kind regards ...
May 25 '07 #4

P: 1
It works, I just added:

Expand|Select|Wrap|Line Numbers
  1. onclick="this.value='';"
  2.  
Thanks a lot!
MALI
Feb 17 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.