Forum Moderators: open

Message Too Old, No Replies

text field name should disappear

         

happybuddha1

2:31 pm on Jul 5, 2006 (gmt 0)

10+ Year Member



Dear all,
I tried doing a lot of google and searches on various forums(including this one). However makes me think it is too silly a question to ask.
I was wondering how this is done.
this is what I have.
<INPUT type="text" name="cname" size="12" value="Enter your name">
Now when this is displayed in the browser, and as soon as I try to update the field. the "Enter your name" should disappear. Not happening as of now.
I thought I would do a javascript and ..onMouseClick() set the value to null
would this
be a correct approach?

are there any other ways to do it?

Thanks in advance

Regards
Buddha

oxbaker

5:07 pm on Jul 5, 2006 (gmt 0)

10+ Year Member



why dont you just make a label called name and leave the value blank as to reduce the amount of mistakes your users will make.

ie:

enter your name : [[NAME INPUT BOX HERER]]

mcm

penders

2:53 pm on Jul 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you want to have some initial ("Type your message here") text in your element to prompt your users then yes, you need to clear it using JavaScript in the onfocus event (as they could click or tab to the control). You could also style your 'prompt' as a faint #cccccc or something as well, to distinguish it from normal typed text.

You also only want to do this the first time they enter the control, as it will clear what they typed!

// Assign the event when document loads
var x = document.getElementById('cname'); // NB: set **ID** of object
if (x!= null) {
x.onfocus = initTextArea;
}

// Clears textarea and changes style when clicked on for the first time
function initTextArea() {
this.onfocus = null;// Clear event so won't call again
this.value = '';
this.style.color = '#000000';// It could be styled initially as #cccccc;
}

You will also need to modify your form validation, as if "Type your message here" is still in the box then they have not actually entered anything.