473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Clear a field in a form

I need a JavaScript that will allow me to clear a field in a form when I
click an image next to it.

Any help will be greatly appreciated.
Apr 18 '07 #1
5 10964
Bob Sanderson said the following on 4/18/2007 4:19 PM:
I need a JavaScript that will allow me to clear a field in a form when I
click an image next to it.
OK, then write one. Or at least try. This is Usenet, not a help desk.
Any help will be greatly appreciated.
The group FAQ might be a good place to start.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 18 '07 #2
On Apr 18, 9:19 pm, Bob Sanderson <sand...@LUVSPAMsandmansoftware.com>
wrote:
I need a JavaScript that will allow me to clear a field in a form when I
click an image next to it.

Any help will be greatly appreciated.
<input
type="text"
accesskey="s"
maxlength="50"
class="purplepic"
id="q"
name="q"
onblur="if(this.value=='')this.value='click here search our
site...';this.className='purplepic';"
onfocus="if(this.value=='click here search our
site...')this.value='';this.className='redpic';ret urn true;"
value="click here search our site..."
/>

<a
title="click here to clear the search box"
id="reset"
href="javascript:void(0);"
onclick="clearit();return false;">
</a>

use a style sheet to style the link, or use an image with the onclick
instead.

here's the javascript:

function clearit()
{
var panel = document.getElementById('q');
panel.value='';
panel.focus();
}

Randy will hate this cos it uses gebi, but hey! And this is just a
copy and paste job from 2004, there are more "modern" unobtrusive
methods to do this, left as an exercise for the OP.

Apr 18 '07 #3
shimmyshack said the following on 4/18/2007 6:27 PM:

<snip>
Randy will hate this cos it uses gebi, but hey!
Nah, I don't care if people use a crutch :)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 18 '07 #4
Lee
shimmyshack said:
>
On Apr 18, 9:19 pm, Bob Sanderson <sand...@LUVSPAMsandmansoftware.com>
wrote:
>I need a JavaScript that will allow me to clear a field in a form when I
click an image next to it.

Any help will be greatly appreciated.

<input
type="text"
accesskey="s"
maxlength="50"
class="purplepic"
id="q"
name="q"
onblur="if(this.value=='')this.value='click here search our
site...';this.className='purplepic';"
onfocus="if(this.value=='click here search our
site...')this.value='';this.className='redpic';re turn true;"
value="click here search our site..."
/>

<a
title="click here to clear the search box"
id="reset"
href="javascript:void(0);"
onclick="clearit();return false;">
</a>

use a style sheet to style the link, or use an image with the onclick
instead.

here's the javascript:

function clearit()
{
var panel = document.getElementById('q');
panel.value='';
panel.focus();
}

Randy will hate this cos it uses gebi, but hey! And this is just a
copy and paste job from 2004, there are more "modern" unobtrusive
methods to do this, left as an exercise for the OP.
I can't speak for Randy, but it's lousy code.
You abuse a link just for a side-effect and then use the least
efficient way to access the field.
--

Apr 18 '07 #5
On Apr 19, 12:21 am, Lee <REM0VElbspamt...@cox.netwrote:
shimmyshack said:


On Apr 18, 9:19 pm, Bob Sanderson <sand...@LUVSPAMsandmansoftware.com>
wrote:
I need a JavaScript that will allow me to clear a field in a form when I
click an image next to it.
Any help will be greatly appreciated.
<input
type="text"
accesskey="s"
maxlength="50"
class="purplepic"
id="q"
name="q"
onblur="if(this.value=='')this.value='click here search our
site...';this.className='purplepic';"
onfocus="if(this.value=='click here search our
site...')this.value='';this.className='redpic';ret urn true;"
value="click here search our site..."
/>
<a
title="click here to clear the search box"
id="reset"
href="javascript:void(0);"
onclick="clearit();return false;">
</a>
use a style sheet to style the link, or use an image with the onclick
instead.
here's the javascript:
function clearit()
{
var panel = document.getElementById('q');
panel.value='';
panel.focus();
}
Randy will hate this cos it uses gebi, but hey! And this is just a
copy and paste job from 2004, there are more "modern" unobtrusive
methods to do this, left as an exercise for the OP.

I can't speak for Randy, but it's lousy code.
You abuse a link just for a side-effect and then use the least
efficient way to access the field.

--
javascript when it isnt used unobtrusively is indeed an abuse; as is
buffing one's own ego while sitting on the other hand.
Apr 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Targa | last post by:
How can I clear a text field by clicking on a button? Ive searched the web and found tons of scripts that will clear text just entered but I am displaying results from a database into a text area...
5
by: Jack | last post by:
Hi, I am trying to get a thorough understanding of a code where a addition or deletion of records can be done from a list of records. For addition part of the form, data is being obtained from set...
3
by: Jake | last post by:
How can I have an image that when clicked would clear my textarea field? The textarea field is the only element in my form and has a default value - a couple lines of text.. I tried using a...
0
by: Doslil | last post by:
I have a form which is designed to only data entery.When i try to open to form in the run form I have the following errors 1. when i open the form I get an error message saying "Access can't...
0
by: Doslil | last post by:
I have a form which is designed to only data entry. I have written the following code in the key press event of the employee number to allow the user to enter only numbers in this field. If...
0
by: Cleako | last post by:
Here is my dilema. I have a validation summary that I use soley for my Required Field Validators. I have it setup to run from a Page.Validate call in the code-behind, this is because I need to...
2
by: Tom | last post by:
Just wondering what others were doing to clear the errorprovider? What I mean is that, during processing of a windows form, I may turn on (i.e. SetError) the errorprovider for various fields. Now,...
2
by: tkhouk | last post by:
I have a small form with two unbound look-up fields (one for an ID and one for last name). Each unbound field has a command button that actually goes to my table and brings in the records. How can...
5
by: karsagarwal | last post by:
I have a bounded form and after I click the button to update/save. THe fields are still there. Is there a way to clear off the fields in the bounded form. Thanks, SA Here's the code that I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.