Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-06-2012, 09:34 AM   PM User | #1
fscaint
New Coder

 
Join Date: Oct 2011
Posts: 22
Thanks: 17
Thanked 0 Times in 0 Posts
fscaint is an unknown quantity at this point
on Field Test How to clear value onclick?

Hello,
i Have problem about clear value when ppl input data on text field
Any idea?

Code:
 
<form action="http://www.packagetrackr.com/track/" method="get" name="track" target="_blank">
<div class="form-field-error-message hidden" style="display: none; ">
<div class="CommonEmptyTrackingNumber"></div>
</div>

<div id="track-form-tracking-number-container">
  <div id="track-form-tracking-number-inner-container" class="track-form-control-boxer"><input id="track-form-tracking-number" class="track-form-element " type="text" name="n" value="Type a tracking number" title="Type a tracking number..." onFocus="if(/^Type a tracking number...$/i.test(this.value)){this.value='';}" onBlur="if(this.value==''){this.value='Type a tracking number...';}">
  <input value="Track!" name="submit" type="submit" title="Track your package" class="track-form-submit-button sprite-master">
</div>
</div>
<div id="track-form-jss-carrier-container" class="hidden" style="z-index: 1000; display: none; ">
<div id="track-form-jss-carrier-content">
<label id="jss-carrier-auto" class="track-form-jss-carrier-label jss-carrier-label">
<input id="jss-carrier-auto-value" value="" type="radio" name="c" checked="checked"> <span>Auto Detect Carrier</span>
</label>
</div>
</div>
</form>
fscaint is offline   Reply With Quote
Old 04-06-2012, 03:09 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
why not do the same as you do onBlur, but in reverse?
Code:
onFocus="if(this.value=='Type a tracking number'){this.value=''}"
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
fscaint (04-06-2012)
Old 04-07-2012, 12:26 AM   PM User | #3
dave_UK
New Coder

 
Join Date: Mar 2012
Posts: 33
Thanks: 6
Thanked 1 Time in 1 Post
dave_UK is an unknown quantity at this point
i would also use

Code:
autocomplete="off"
This clears Text from Input boxes on Refresh and stops Input Boxes from Saving previous inputs
dave_UK is offline   Reply With Quote
Users who have thanked dave_UK for this post:
fscaint (04-13-2012)
Old 04-07-2012, 01:50 AM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Your regex doesn't match the element's default value (...)

Do it like this: onfocus="if(this.value == this.defaultValue){this.value='';}"

From which you can work out how to code an onblur event handler that restores the original text if nothing is entered.
Logic Ali is offline   Reply With Quote
Old 04-13-2012, 08:47 AM   PM User | #5
fscaint
New Coder

 
Join Date: Oct 2011
Posts: 22
Thanks: 17
Thanked 0 Times in 0 Posts
fscaint is an unknown quantity at this point
Quote:
Originally Posted by Logic Ali View Post
Your regex doesn't match the element's default value (...)

Do it like this: onfocus="if(this.value == this.defaultValue){this.value='';}"

From which you can work out how to code an onblur event handler that restores the original text if nothing is entered.
missing text / delete by accident the element's default value (...) that why the script doesn't work properly, LOL

RESOLVED

Last edited by fscaint; 04-13-2012 at 08:48 AM.. Reason: corect text
fscaint is offline   Reply With Quote
Old 04-13-2012, 12:50 PM   PM User | #6
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
HTML5 supports placeholder attribute to provide hint to the input fields.

Code:
<input type="text" name="n" placeholder="Type a tracking number"  />
There are a lot of plugins out there to make this cross-browser compatible. Here's one of them:

http://davidwalsh.name/html5-placeholder
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:24 PM.


Advertisement
Log in to turn off these ads.