/    Sign up×
Community /Pin to ProfileBookmark

Delete text by clicking

Hi there, I’d like to display this textarea with an initial text, and I’d like it to be deleted if the user click into the text area. Would be even better if the text would look like it is selected.

<input name=”p_shout” type=”text” value=”enter your text here” size=”20″>

I failed to find anything similar on the web ?

I hope it is a javascript thing, and it is the place to post this question.
Thank you

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@PittimannMay 11.2004 — Hi!

Example:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
.high{
background-Color: Highlight ;
color: HighlightText;
}
.low{
background-Color: #FFFFFF;
color: #000000;
}
-->
</style>

<script language="JavaScript" type="text/javascript">
<!--
function deleteDefaultText(field){
if(field.value=="enter your text here"){
field.value="";
field.className="low";
}
}
//-->
</script>
</head>
<body>
<form>
<input name="p_shout" type="text" value="enter your text here" size="20" onfocus="deleteDefaultText(this)" class="high">
</form>
</body>
</html>[/code]
Cheers - Pit
Copy linkTweet thisAlerts:
@theBody44May 11.2004 — Try this...Insert this function into the <head>...

function cutIt(){

var t = document.myForm.myText;

if (t.value == "Original Text"){

t.value = "";

}

else{

t.select();

}

}

Then put this into the <body>...


<form name="myForm">

<textarea name="myText" onFocus="cutIt()" value="Original Text"></textarea>

</form>

If the value of your text area is the initial value, it will delete the text. If it's anything else, the text will be selected/highlighted.
Copy linkTweet thisAlerts:
@PaleeauthorMay 11.2004 — geez, y'all so quick! thank you!

just what i need! thank you!
Copy linkTweet thisAlerts:
@PittimannMay 11.2004 — Well - as far as my part is concerned:

You're welcome ?!

Cheers - Pit
Copy linkTweet thisAlerts:
@VladdyMay 11.2004 — And a simple way:

<textarea onclick="this.value=''; this.onclick=function(e){return true;};">Initial Text</textarea>

BTW language attribute of the script element has been deprecated last century :rolleyes:
Copy linkTweet thisAlerts:
@PittimannMay 11.2004 — Hi![i]Originally posted by Vladdy [/i]

[B]BTW language attribute of the script element has been deprecated last century :rolleyes: [/B][/QUOTE]
So what? Some browsers which have been invented millenniums ago have survived until now and do not know how to deal with the type attribute...

Cheers - Pit
Copy linkTweet thisAlerts:
@VladdyMay 11.2004 — [i]Originally posted by Pittimann [/i]

[B]Hi!So what? Some browsers which have been invented millenniums ago have survived until now and do not know how to deal with the type attribute...



Cheers - Pit [/B]
[/QUOTE]

Those browsers should not be dealing with JS in the first place....
Copy linkTweet thisAlerts:
@PittimannMay 11.2004 — Hi!

Even though it is eternities ago: do you know, for which browser(s) js was "invented"?

Cheers - Pit
Copy linkTweet thisAlerts:
@VladdyMay 11.2004 — [i]Originally posted by Pittimann [/i]

[B]Hi!



Even though it is eternities ago: do you know, for which browser(s) js was "invented"?



Cheers - Pit [/B]
[/QUOTE]

We are not using vehicles for which the wheel was invented, are we?
Copy linkTweet thisAlerts:
@PittimannMay 11.2004 — Hi!We are not using vehicles for which the wheel was invented, are we?[/QUOTE]I guess, we both don't ?; but if you go somewhere else, you will find people still using such vehicles. And as far as browsers are concerned: there are still people using browsers for which to enhance js was invented.Those browsers should not be dealing with JS in the first place....[/QUOTE]Why? Because you say so??? :rolleyes:

Cheers - Pit
Copy linkTweet thisAlerts:
@VladdyMay 11.2004 — [i]Originally posted by Pittimann [/i]

[B]Hi!I guess, we both don't ?; but if you go somewhere else, you will find people still using such vehicles. And as far as browsers are concerned: there are still people using browsers for which to enhance js was invented.Why? Because you say so??? :rolleyes:



Cheers - Pit [/B]
[/QUOTE]

No because it is not worth the trouble.

A page has to function [b]without[/b] javascript, and that is what the law (in most civilized countries) says. You can write DOM compliant script (with a few IE workarounds) to [b]enhance[/b] your page that will work on 90% of JS enabled browsers. For every other 1-2% of the browsers you have to double your code and double your development time. Not only you/your customer suffers from unjustified expence and bandwidth, but the 90% of users get bloated code that slows down the page (both download and execution).

The only efficient way is to give the browser that does not understand document.getElementById() the page with basic functionality (JS disabled).
×

Success!

Help @Palee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...