Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript clear single text field

Posted on 2009-04-06
4
Medium Priority
?
840 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
[X]
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
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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 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