Solved

javascript clear single text field

Posted on 2009-04-06
4
827 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 to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
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 the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now