Solved

javascript clear single text field

Posted on 2009-04-06
4
835 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 500 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

808 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