Forum Moderators: open

Message Too Old, No Replies

form field values

         

Geoffrey james

10:20 am on Oct 16, 2006 (gmt 0)

10+ Year Member



hi all,

i have created a form which, on this site i want the desciption of each feild within the box,
ie: Name
Email.....and so on.

Some may think why not use <label for=""> tags or place the box descriptions outside, and although I have done this most times before i want a different look this time.

What i want to know though is how to make the text within the box disappear when the user clicks on to fill their details in. At the moment im having to delete say...Name, then fil in my name.

thanks for any help.

geoff

JAB Creations

4:56 pm on Oct 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Geoffrey,

What is a tag? Perhaps you were speaking about elements? Correct syntax, correct references, correct questions, get correct answers. ;)

Anyway ... are you asking to make the label's text disappear or change when the user types something in to the input field?

- John

XHTML Minimal code...

<form action="" method="post">
<fieldset>
<label for="example">your field description</label><input id="example" name="example" type="text />
</fieldset>
</form>

milanmk

5:21 pm on Oct 16, 2006 (gmt 0)

10+ Year Member



I think you are talking about the following JavaScript effect.


<html>

<head>
<script>
function clear(field)
{
if (field.defaultValue == field.value)
field.value = ""
}
</script>
</head>

<body>

<form>
<input type="text" value="Search" onfocus="clear(this)">
</form>

</body>

</html>

Hope this helps.

Milan

Geoffrey james

9:42 pm on Oct 16, 2006 (gmt 0)

10+ Year Member



sorry JAB Creations

<form action="" method="post">

<input name="name" type="text" value="name">

in this example I place the text 'name within the box which I want to dissapear when the used clicks on the mouse to add their details.

Geoff

Geoffrey james

9:56 pm on Oct 16, 2006 (gmt 0)

10+ Year Member



Hi milanmk,

tried the code but to no avail,

<head>
<script>
function clear(field)
{
if (field.defaultValue == field.value)
field.value = ""
}
</script>
</head>

<body>

<form action=""....blar blar>

<input name="name" type="text" id="name" value="name" onFocus="clear(this)">

<input name="telephone" type="text" value="telephone" onFocus="clear(this)">

<input name="email" type="text" value="email" onFocus="clear(this)">

</form>

</body>

have I done something wrong, any thoughts?

cheers for help geoff

milanmk

10:35 pm on Oct 17, 2006 (gmt 0)

10+ Year Member



The problem was with function name clear. Try this new code.


<head>

<script>
function clearValue(field)
{
if (field.defaultValue == field.value)
field.value = "";
}
</script>

</head>

<body>

<form action="">
<input name="name" type="text" id="name" value="name" onFocus="clearValue(this)">
<input name="telephone" type="text" value="telephone" onFocus="clearValue(this)">
<input name="email" type="text" value="email" onFocus="clearValue(this)">
</form>

</body>

Milan

kaled

12:36 am on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't use the value "name" as a field/object name since it will conflict with the name value/attribute of the form.

e.g.

<input name="[red]myName[/red]" type="text" id="name" value="name" onFocus="clear(this)">

Kaled.

Geoffrey james

6:15 am on Oct 18, 2006 (gmt 0)

10+ Year Member



Cheers milanmk/kaled

This now works great, you guys must feel great everytime you help a newbie get something fixed, I've not been doing me website for long, but managed to help someone the other day, only a simple thing but felt really great, I hope I can help others as i go along.

cheers geoff