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


Groups > comp.lang.javascript > #37888

Re: Get user input without PHP code?

Path csiph.com!weretis.net!feeder7.news.weretis.net!news.mb-net.net!open-news-network.org!.POSTED.2.226.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Get user input without PHP code?
Supersedes <2522463.mvXUDI8C0e@PointedEars.de>
Date Thu, 28 Nov 2019 18:42:04 +0100
Organization PointedEars Software (PES)
Lines 63
Message-ID <11431325.O9o76ZdvQC@PointedEars.de> (permalink)
References <1fd6cda2-34cc-4389-93b9-1ac2176c8afd@googlegroups.com> <w5bmsjajroil.vdgzdmfek55v$.dlg@40tude.net>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
Injection-Info gwaiyur.mb-net.net; posting-host="2.226.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch:178.197.226.2"; logging-data="14855"; mail-complaints-to="abuse@open-news-network.org"
User-Agent KNode/4.14.10
Cancel-Key sha1:nXZPjs9q7yfz9EBLwrKWx/blaco=
Cancel-Lock sha1:4QRIH2yw0LRXHkjcMFkp45SfcnI=
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
X-User-ID U2FsdGVkX18+JsgjljGKtaJOH+bp5SwRCEbuhpQWaNRQiXQke0OhUg==
Xref csiph.com comp.lang.javascript:37888

Show key headers only | View raw


JJ wrote:

> On Wed, 27 Nov 2019 11:56:40 -0800 (PST), RG III wrote:
>> I've been away from HTML/JavaScript/PHP coding for awhile, so I don't
>> know how much has changed in the web coding world... I'm just curious,
>> but are there any HTML or JavaScript methods for getting user input
>> without using input forms or PHP back-end coding?
> 
> If it's just text input, then aside from what already have been mentioned,
> additionally, `keypress` or `keydown` event can be used to listen for key
> presses. At the proper time, of course. Then send the text to the server
> using AJAX.

This advice is outdated in several respects.

It is better to listen to the “beforeinput” and “input” events, and to the 
“keypress” event only as a fallback, because the former are only fired if 
something changes without the input control losing focus; and they are also 
fired if text is edited using the clipboard (using either a keyboard or a 
pointing device), which is not always and everywhere the case with the 
“keypress”, “keydown” and “keyup” events.

Notably, the “keydown” event and the (not mentioned, but more appropriate 
than that) “keyup” event, and sometimes the “keypress” event, are also fired 
if the value of a control does not change, for example if the Backspace key 
is pressed in an empty input control or a key is pressed in an 
input/textarea control but the maximum number of allowed characters has been 
reached (“maxlength” attribute).  So using those events in client–server 
communication incurs an unnecessary load on the server.

Finally, (outside the jQuery information bubble) nowadays one no longer 
speaks of “AJAX” (which once meant “Asynchronous JavaScript and XML”), but 
of submitting data or fetching a Web resource asynchronously (via HTTP), 
preferably using the Fetch API; where it should be noted that ECMAScript 
2018 introduced the “await” operator and “async” keyword as syntactic sugar 
for processing the returned promise (no more callbacks for simple tasks):

  (async function () {
    var response = await fetch('/query?format=json');
    var obj = await response.json();

    /* executed after the response was received */
    console.log(obj);
  }());

  /* executed before the response is received */
  console.log(42);
​
<https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event>

<https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event>

<https://developer.mozilla.org/en-US/docs/Web/API/Document/keypress_event> 
(deprecated)

<https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API>

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await>
 
-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
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

Get user input without PHP code? RG III <mob.rrr.3@gmail.com> - 2019-11-27 11:56 -0800
  Re: Get user input without PHP code? Martin Leese <please@see.Web.for.e-mail.INVALID> - 2019-11-27 13:34 -0700
  Re: Get user input without PHP code? Robert Heller <heller@deepsoft.com> - 2019-11-27 15:09 -0600
  Re: Get user input without PHP code? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-11-27 14:49 -0800
  Re: Get user input without PHP code? JJ <jj4public@vfemail.net> - 2019-11-28 23:44 +0700
    Re: Get user input without PHP code? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-11-28 18:42 +0100
  Re: Get user input without PHP code? Arno Welzel <usenet@arnowelzel.de> - 2019-11-29 11:49 +0100

csiph-web