Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #7609
| From | Dr J R Stockton <reply1142@merlyn.demon.co.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Clear field with Javascript - use of variable? |
| Date | 2011-10-21 21:53 +0100 |
| Organization | Home |
| Message-ID | <G+ZOmME+udoOFwRj@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | <j7q78d$mn7$1@dont-email.me> |
In comp.lang.javascript message <j7q78d$mn7$1@dont-email.me>, Fri, 21
Oct 2011 00:27:23, Garry Jones <garry@garryjones.se> posted:
>I need to expand a function and a user button that clears an input
>field and sets focus.
> ...
>Instead of writing a seperate function for each input field I would
>like to use the same one and pass a variable from each link. Can
>someone point me in the right direction as I am having problems finding
>a good site with simple instructions for this.
function cfld() {
document.getElementById("newsinl").value="";
document.getElementById("newsinl").focus();
}
should. for readability, writeability, and efficiency, be
function cfld() { var X = document.getElementById("newsinl")
X.value="";
X.focus();
}
That is easily changed to
function cfld(X) {
X.value="";
X.focus();
}
now called by cfld(document.getElementById("newsinl"))
which can if beneficial be called by
function CFLD(S) { cfld(document.getElementById(S))
but can be called directly and given a reference to the input control.
You should have read the section of the FAQ entitled "Getting a
Reference to an Element", except that it does not exist there, so if you
have trouble with the above read instead section "Getting a Reference to
a Page Element" in page <http://www.merlyn.demon.co.uk/js-faq-u.htm>.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE8 FF3 Op12 Sf5 Cr12
news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
<http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar
Clear field with Javascript - use of variable? "Garry Jones" <garry@garryjones.se> - 2011-10-21 00:27 +0200
Re: Clear field with Javascript - use of variable? Tim Streater <timstreater@greenbee.net> - 2011-10-20 23:53 +0100
Re: Clear field with Javascript - use of variable? Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-10-21 11:24 +0200
Re: Clear field with Javascript - use of variable? Dr J R Stockton <reply1142@merlyn.demon.co.uk> - 2011-10-21 21:53 +0100
Re: Clear field with Javascript - use of variable? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-22 01:17 +0200
csiph-web