Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18117

Re: Want to construct a function instead of the code for onkeyup

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <37748651.8yA5jalnsy@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Wed, 16 Jan 2013 23:29:51 +0100
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
Subject Re: Want to construct a function instead of the code for onkeyup
Newsgroups comp.lang.javascript
References <kd77dq$tph$1@dont-email.me>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 41
NNTP-Posting-Date 16 Jan 2013 23:29:51 CET
NNTP-Posting-Host 5f81b176.newsspool4.arcor-online.net
X-Trace DXC=Z@l<RdjL^2cfF8a^:6>b7e4IUK<Cl32<a4Fo<]lROoRa8kF<OcfhCOkH?bDQ\Zh=?iDZm8W4\YJNlb@mF9jNikdeWWB88<dh9WeG?;Jon:L\cm
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:18117

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Tony Johansson wrote:

> How should I write a function if I want to move the code
> that is executed for onkeyup ?
> 
> <input type="text"  name="depthBow" id="txtDepthBow" size="20"
>    onkeyup="if (/[^0-9\.,]/g.test(this.value))
>    this.value = this.value.replace(/[^0-9\.,]/g,'')" />

You should pass the “this” value, here a DOM object reference, as argument 
to the function:

<https://developer.mozilla.org/en-
US/docs/JavaScript/Reference/Functions_and_function_scope>

<http://jibbering.com/faq/>
<http://PointedEars.de/faq>

And do not use the RegExp flag “g(lobal)” with RegExp.prototype.test(), as 
it is a wrapper around RegExp.prototype.exec() [ES 5.1, § 15.10.6.3]:

  var rx = /x/g;

  /* true */
  rx.test("x")
  
  /* false */
  rx.test("x")

  /* true */
  rx.test("x")

That another /RegularExpressionLiteral/ creates a new RegExp object is a 
change from ECMAScript Ed. 3 to 5 [Annex E]; do not rely on it unless you 
know what you are doing.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Want to construct a function instead of the code for onkeyup "Tony Johansson" <johansson.andersson@telia.com> - 2013-01-16 22:51 +0100
  Re: Want to construct a function instead of the code for onkeyup Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-16 23:29 +0100
    Re: Want to construct a function instead of the code for onkeyup "Tony" <tony.johansson@inport.com> - 2013-01-17 09:10 +0100
      Re: Want to construct a function instead of the code for onkeyup "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-17 15:40 +0100
    Re: Want to construct a function instead of the code for onkeyup "Tony" <tony.johansson@inport.com> - 2013-01-17 09:23 +0100

csiph-web