Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

javascript clear single text field

Posted on 2009-04-06
4
Medium Priority
?
842 Views
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>
0
Comment
Question by:webdork
  • 2
4 Comments
 
LVL 41

Expert Comment

by:HonorGod
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"

e.g.,

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

Author Comment

by:webdork
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>

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

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 24081029
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
 

Author Closing Comment

by:webdork
ID: 31567174
That did it.

Thank you.

WD
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

916 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