how to empty a textbox when a button is clicked

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

how to empty a textbox when a button is clicked

Post by vigge89 »

How can I empty a textbox trough JS when a button is clicked (form submitted)?
this is probably very easy, but i know nothing about JS, so i have no idea...
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

document.GetElementbyId('textbox').value = "";

but shouldn't it be emptied by default?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

no, you see, the form is on the main 'window', but then it's target is an iframe, so the text stays...
but i'll try your code out, thanks!
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

doesn't seem to work, I use this:

Code: Select all

function clear_field(field) {
document.GetElementbyId(field).value = '';
}
but when i call the function trough:

Code: Select all

OnClick="javascript:clear_field('shout_message');"
it doesn't work
the textbox is named and got the id 'shout_message', but it still doesn't work...
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

anyone?
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

try this:

<input type="" onfocus="this.value=''"> <----- single line entry.

or

<textarea onfocus="this.value=''"> <----- multi line entry.

There is no complex script needed really. Just clear the text area with onfocus.

BTW, you can also add a value to the onfocus, ie, onfocus="this.value=''Put Your Text Here"

Hope This Helps :)
Post Reply