#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    46
    Rep Power
    10

    Unhappy How do I get around this behavior of HTML?


    I have a little test code at: http://www.opednews.com/populum/test.html

    This is the exact code:

    Code:
    <form style="margin-bottom:8px;" onsubmit="fred(); return false;">
    	<input type="text" style="font-size:8pt;" id="smallreply" size="50" value="Write a Reply..." onFocus="this.value='';">
    </form>
    When you enter characters into the field, and then go off to another browser or tab; and then come back, what you entered is gone.

    I just discovered that after entering some data, when you go off and then return, the onfocus is re-activated, which clears the field. Again.

    OK. I get it. So how can you have some pre-defined text, clear it when you start typing, but not have the above happen?

    Any ideas?

    Thanks

    ....Vidya
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by vidyaishaya
    I have a little test code at: http://www.opednews.com/populum/test.html

    This is the exact code:

    Code:
    <form style="margin-bottom:8px;" onsubmit="fred(); return false;">
    	<input type="text" style="font-size:8pt;" id="smallreply" size="50" value="Write a Reply..." onFocus="this.value='';">
    </form>
    When you enter characters into the field, and then go off to another browser or tab; and then come back, what you entered is gone.

    I just discovered that after entering some data, when you go off and then return, the onfocus is re-activated, which clears the field. Again.

    OK. I get it. So how can you have some pre-defined text, clear it when you start typing, but not have the above happen?

    Any ideas?

    Thanks

    ....Vidya
    If you're sure that the predefined text is going to be the same every time, you could check for it onFocus. Ie:

    Code:
    <input type="text" style="font-size:8pt;" id="smallreply" size="50" value="Write a Reply..." onFocus="if (this.value == 'Write a Reply...') {this.value=''};">
    Not sure offhand if onfocus will let you be that elaborate; if not, you could write the if clause in a function and then call that function onfocus.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    46
    Rep Power
    10

    Talking Thanks, good idea. I did solve this, though.


    Turns out that all I needed to do was use this onfocus clause:

    Code:
    onFocus="this.value='';this.onfocus='';"

IMN logo majestic logo threadwatch logo seochat tools logo