how to create onclick event?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

how to create onclick event?

Post by adsegzy »

I want an onclick event such that, when my visitors click on any field on my form, the default value disappears.

adsegzy
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: how to create onclick event?

Post by JAB Creations »

Code: Select all

<input onclick="alert('replace this alert with a function');" />
You could use addEventListener (and addEvent for IE) though I think you'll need to figure out the basics first.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to create onclick event?

Post by VladSun »

You'd better use the onfocus event (Tab navigation ;) )
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: how to create onclick event?

Post by JAB Creations »

Agreed, I love sites that utilize blur and focus events. :drunk:
frao_0
Forum Commoner
Posts: 27
Joined: Sat Aug 08, 2009 3:52 am
Location: Toulouse, France

Re: how to create onclick event?

Post by frao_0 »

w3c say not to use inline CSS and JavaScript, which is sometimes a pain in the ass. But it would give something like this if your element has, let's say, an id value of 'myID'

Code: Select all

onload=function()
{
document.getElementById('myId').onclick=function()
{
this.value=''
}
}
Post Reply