javascript clear single text field

Posted on 2009-04-06
Last Modified: 2012-05-06
I want to clear a single form field (text) with a hyperlink.
Something like this:
<a href="javascript:form1.datefield.value=' ' " >clear date</a>
Question by:webdork
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 41

Expert Comment

ID: 24080809
What's the problem.  That looks like it should work,
as long as:

The form has a "name" attribute of "form1", e.g.,

<form name="form1" ...>

and the input field has a "name" attribute of "datefield"


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

Author Comment

ID: 24080914
Its a syntax error. must be with the quote double quote

Ive tried
<a href='javascript:form1.USWP_Expiry.value=""' >clear date</a>

<a href="javascript:form1.USWP_Expiry.value= ' ' " >clear date</a>
LVL 75

Accepted Solution

Michel Plungjan earned 500 total points
ID: 24081029

<a href="#" onClick="document.form1.datefield.value=''; return false " >clear date</a>

for a NAMED form with a NAMED field


<a href="#" onClick="document.getElementById('datefield').value=''; return false " >clear date</a>
for a field with an ID

Note that the ='' are two single quotes

Author Closing Comment

ID: 31567174
That did it.

Thank you.


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change the background and font colors in Notepad++ 5 207
PowerShell and cisco ios 3 70
Powershell Split 18 43
Notepad++ Question 11 28
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at (http://www.experts-ex…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question