Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Dr J R Stockton Newsgroups: comp.lang.javascript Subject: Re: Clear field with Javascript - use of variable? Date: Fri, 21 Oct 2011 21:53:18 +0100 Organization: Home Lines: 48 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain;charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="UwYDIHu13GPq28RciNoAJA"; logging-data="30494"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Tl/Nw176458N+s8M6hQ3NBt41+/XjD3Q=" User-Agent: Turnpike/6.05-S () Cancel-Lock: sha1:Uhzqf4Vo+Fez4SphRFZmr5juOjw= Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:7609 In comp.lang.javascript message , Fri, 21 Oct 2011 00:27:23, Garry Jones 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 . -- (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE8 FF3 Op12 Sf5 Cr12 news:comp.lang.javascript FAQ . jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links.