A little java help??

S

sally jo

What is the code that you use to put words int he input box that
disappear when the user starts typing??
 
V

Vince Morgan

sally jo said:
What is the code that you use to put words int he input box that
disappear when the user starts typing??
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title></title>
<script type="text/javascript">
function doSelect(obj) {
obj.focus();
obj.select();
}
</script>
</head>
<body onload="doSelect(document.getElementById('inp1'));">
<div>
<input id="inp1" value="This is the text."/>
</div>
</body>
</html>

HTH
Vince Morgan
 
?

=?ISO-8859-1?Q?Olli_M=E4ntyranta?=

sally said:
What is the code that you use to put words int he input box that
disappear when the user starts typing??
Or this:

<html><head><title></title>
<script type="text/javascript">
function ClearText(){
document.theBigForm.theField.value = "";
}
</script>
</head>
<body>
<form action="some.cgi" name="theBigForm">
<input id="inp1" value="hiihoo" name="theField"
onfocus="ClearText()"/>
</form>
</body>
</html>

rgrds,

Olli
 
N

nice.guy.nige

While the city slept, Olli Mäntyranta ([email protected]) feverishly
typed...
sally said:
What is the code that you use to put words int he input box that
disappear when the user starts typing??
[...]
function ClearText(){
document.theBigForm.theField.value = "";
}
[...]

The only problem with this code is that it will clear the textbox everytime
it is clicked on. Say for example I put some text in there, carry on with
the form, then notice I've made a typo in that field. I click on it to
change it and voila! Everything I typed before has vanished!

Maybe something like;

<script type="text/javascript">
<!-- Hide

var firstTime = true;
function clearText()
{
if(firstTime) {
document.theBigForm.theField.value = "";
firstTime = false;
}
}

// Dunhindin -->
</script>

I've not put that to the test mind, and it is a while since I did any JS...

Cheers,
Nige
 
J

Jukka K. Korpela

Scripsit nice.guy.nige:
While the city slept, Olli Mäntyranta ([email protected]) feverishly
typed...
sally said:
What is the code that you use to put words int he input box that
disappear when the user starts typing??
[...]
function ClearText(){
document.theBigForm.theField.value = "";
}
[...]

The only problem with this code is that it will clear the textbox
everytime it is clicked on.

No, the problem is that it sometimes "works". Therefore it lets the author
preserve the impression of being clever and doing the right thing. Well, it
also wipes our user input, of course, at times.
if(firstTime) {
document.theBigForm.theField.value = "";
firstTime = false;
}

It does not help against the problem that the user starts typing and then
the JavaScript code starts executing and kills his input. Of course, if the
author is slow in typing, he never realizes this.

So the clue is that the original idea, which creates the problem, should be
abandoned. Do _not_ put any initial content in a textfield, unless it is a
meaningful default, and then you surely don't want to remove it when the
user focuses on the field.

Instead, use meaningful labels and, if needed, explanations - before the
textfield.
 
N

nice.guy.nige

While the city slept, Jukka K. Korpela ([email protected]) feverishly
typed...
It does not help against the problem that the user starts typing and
then the JavaScript code starts executing and kills his input. Of
course, if the author is slow in typing, he never realizes this.

Eh? How is this going to kill the user's input? The script is fired when the
field acquires focus, not at any other time. Are you getting this confused
with forms which give focus to a particular field when the page has loaded
(using the onload handler in the body element)? If so, that is a particular
bugbear of mine and one which I addressed in here long ago:
http://www.html-faq.com/htmlforms/?entryfocus

Cheers,
Nige
 
J

Jukka K. Korpela

Scripsit nice.guy.nige:
Eh? How is this going to kill the user's input?

Among other things, the way you explained in your earlier message.
The script is fired
when the field acquires focus, not at any other time.

And you have no way of really knowing when that happens. There's no law
against browsers focusing automatically on the first input field, or on the
first focusable element.
 
N

nice.guy.nige

While the city slept, Jukka K. Korpela ([email protected]) feverishly
typed...
Scripsit nice.guy.nige:


Among other things, the way you explained in your earlier message.
Explain


And you have no way of really knowing when that happens. There's no
law against browsers focusing automatically on the first input field,
or on the first focusable element.

In which case, the "default" content will be deleted. Once. End of story.
Again, how will a script that is called by the onfocus handler on an input
field result in the user's legitimate input being deleted??????
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top