Forum Moderators: open

Message Too Old, No Replies

Clearing an input form (html,php,javascript

calling a javascript function from a input form

         

pascy

9:17 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



hello,

I have a working javascript function which clears the default value of an inputfield onFocus.
Now I built a php script around the input element:
I do not get any error, but onFocus/clearme does not work anymore :-(

<input type="text" name="name" value="name" onFocus="clearme(fe,'name')" size="20" tabindex=1>

should not be very difficult...

Thanks for your help!

Paul

Bernard Marx

10:02 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Might be more difficult at the moment.

onFocus="clearme(fe,'name')"

What does

clearme
look like?
Does
fe
have a defined value?

pascy

10:30 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



thanks for your fast reply :-)
and thank you very much for your hint!
I am obviously to tired:
you see my function down below, everything is alright:
I do not know how, but I messed around with the code I think.
The call in the Input field has to be THIS instead of fe (field element):
... onFocus="clearme(THIS, 'name')"...

>>>> but maybe you have also an idea because of my other posting:
[webmasterworld.com...]

this is my javascript block in the HTML <HEAD>

...
<script language="JavaScript">
function clearme(fe,txt){
// check to see that the form element is default
if (fe.value == txt){
// clear the default text
fe.value = "";
}
return;
}
</script>
</head>

and the call is

Bernard Marx

11:17 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



..is?

I'm a bit tired too .. for looking at all that php.

onFocus="clearme(THIS, 'name')"...

You mean

[blue]this[/blue]
, I assume?

pascy

11:44 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



hi again:

yes I mean this :-)
Does this make a difference?! HTML is not case-sensitive, so is javascript? :-?
ui ui ui - I have still a lot to learn :-)

I just wrote THIS in uppercase to mark the change.

and the call is as above :-)

Rambo Tribble

2:33 am on Sep 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JavaScript is case-sensitive, as is XHTML or XML. If I read you right, you're just clearing an input field? How about:

<input onfocus="this.value=''" type="text" value="some text" />

(That's two single quotes after this.value=, before the closing double quotes.)

pascy

6:42 am on Sep 17, 2004 (gmt 0)

10+ Year Member



Oh yes, thanks! this looks simple, nice and easy :-)

I think I was too busy with the syntax...

The advantage of "my" method (i copied it from a book) would be, that it only clears the field, if the default value is in the field...
if the user detects an mistake in his input he may return, and has not enter the whole input.

I use my clearme function also in a textarea...

Rambo Tribble

2:02 pm on Sep 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<input onfocus="if(this.value=='some text')this.value=''" type="text" value="some text" />

or, more generically:

<input onfocus="if(this.value==this.defaultValue)this.value=''" type="text" value="some text" />

This approach should also work with a textarea, as I believe it also supports defaultValue.