Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Closed Thread
First click clear text box
Old 07-21-2008, 06:18 PM First click clear text box
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
So the idea is for the first click to clear the text box. Here's the code that I've tried to put together (I'm no Javascripter!)

Code:
var clearedonce = false;
var objcleared = new Array();

function firstClear(obj) {
for (i=0;i<objcleared.length;i++)
{
if(objcleared[i] == obj){
clearedonce = true;
}
}
if(clearedonce == false) {
obj.value = "";
objcleared[] = obj;
}
}
But it doesn't seem to work. Suggestions? Am I thinking too PHP?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 07-21-2008, 06:30 PM Re: First click clear text box
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Would it not be much simpler to use

onfocus="this.select()" on the text box

and let the user decide to clear the entry or not?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
View Public Profile Visit chrishirst's homepage!
 
Old 07-21-2008, 10:02 PM Re: First click clear text box
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
Nice try :P however I am more interested in the first click clear. It's for the Love Calculator after a calculation has been submitted so if they click the field to remove / modify the name it'll be wiped.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
View Public Profile Visit Galaxian's homepage!
 
Old 07-21-2008, 10:54 PM Re: First click clear text box
Super Talker

Posts: 116
Trades: 0
Code:
onfocus="document.getElementById('idname').value=''"
just add id= to ur input box and chnage idname in that code above to be the same as the id name of ur input box.
__________________


Please login or register to view this content. Registration is FREE

nasaboy007 is offline
View Public Profile Visit nasaboy007's homepage!
 
Old 07-22-2008, 02:02 AM Re: First click clear text box
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
That still doesn't achieve what I want. It must be first click after page is loaded note the function + variables.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
View Public Profile Visit Galaxian's homepage!
 
Old 07-22-2008, 02:59 AM Re: First click clear text box
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
This is an idea from my head, and you shouldn't need global vars defined.

Code:
function firstClear(obj)
{
  if(obj.clearThis == undefined)
  {
    obj.value = '';
    obj.clearThis = true;
  }
}
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
View Public Profile
 
Old 07-22-2008, 04:48 AM Re: First click clear text box
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
after a calculation has been submitted so if they click the field to remove / modify the name it'll be wiped
Not quite, the "this.select()" will only select all the text in the field, then the user can overtype the value, edit spelling with the cursor keys or exit the field and leave it untouched.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
View Public Profile Visit chrishirst's homepage!
 
Old 07-22-2008, 11:03 AM Re: First click clear text box
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by mgraphic View Post
This is an idea from my head, and you shouldn't need global vars defined.

Code:
function firstClear(obj)
{
  if(obj.clearThis == undefined)
  {
    obj.value = '';
    obj.clearThis = true;
  }
}
You are a star
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
View Public Profile Visit Galaxian's homepage!
 
Closed Thread     « Reply to First click clear text box
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20053 seconds with 12 queries