• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 844
  • Last Modified:

javascript clear single text field

I want to clear a single form field (text) with a hyperlink.
Something like this:
<a href="javascript:form1.datefield.value=' ' " >clear date</a>
0
webdork
Asked:
webdork
  • 2
1 Solution
 
HonorGodCommented:
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"

e.g.,

<input type="text" name="datefield">
0
 
webdorkAuthor Commented:
Its a syntax error. must be with the quote double quote

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

and
<a href="javascript:form1.USWP_Expiry.value= ' ' " >clear date</a>
0
 
Michel PlungjanIT ExpertCommented:
Better:

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

for a NAMED form with a NAMED field

Or

<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
0
 
webdorkAuthor Commented:
That did it.

Thank you.

WD
0

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now