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


Groups > comp.lang.javascript > #28932

Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect
Date Mon, 30 Nov 2015 22:43:03 +0100
Organization PointedEars Software (PES)
Lines 62
Message-ID <1653278.dNK5XENbKT@PointedEars.de> (permalink)
References <72249e91-27c8-4895-ae4d-f4d974e1b85d@googlegroups.com> <n3h27k$52k$1@news.albasani.net>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1448919785 29012 eJwNyMERACEIA8CaICF65QhI/yWcs78NyFSLCjHmCSv2bAgLjvET8DyZqK/sVUJz2eLNbewfETMQ9w== (30 Nov 2015 21:43:05 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Mon, 30 Nov 2015 21:43:05 +0000 (UTC)
User-Agent KNode/4.14.2
X-User-ID eJwNy8ERAEEEBMCYMOMIZ1nyD+H221VNc/H+4HRwuW3U1BmJDb0Z1/MAtX1N8Lh0ALNidSdPz6u+idT4qCU/Wx4VeA==
Cancel-Lock sha1:t6Licjx9bln8cw6wvjFNze/b/U0=
X-NNTP-Posting-Host eJwFwQkBACAIA8BKDBxSh0f6R/CO5vC+x+mHywWuhJUFNCVHe2CceFQdcO0FN7so/ZBS8gEL/hEH
Xref csiph.com comp.lang.javascript:28932

Show key headers only | View raw


Stefan Weiss wrote:

> On 2015-11-30 05:23, fugee279@gmail.com wrote:
>> <script>
>> $(document).ready(function () {
>>   $('#select_field').change(function(e)

If you must use jQuery, use

  $("#select_field").on("change", function(e) {
    // …
  });

instead.  That code is more efficient (it avoids another wrapper), cleaner 
(event registrations are easy to spot as they look the same), and easier to 
maintain (you can append new event types to the string value).

Also, be as consistent as possible in your string delimiters.  Not only 
makes that code easier to read, but also easier to maintain.

>>    {
>>     if (e.target.value=='select_value') {e.second_field.disabled = true;}
>>   })
>> })
>> </script>
> 
> Next time, please include the error message you see in the console.
> 
> The parameter `e` is the Event object for the change event. This object
> doesn't have a "second_field" property.

Since it is _not_ a reference to an object implementing only the Event 
interface of W3C UI Events, but to a *jQuery* event object, it could have 
that property.

<http://www.w3.org/TR/2015/WD-uievents-20150428/#event-types>
<http://api.jquery.com/category/events/event-object/>

Usually one would send the information in the jQuery event’s extraParameters 
when .trigger()ed, though:

<http://api.jquery.com/trigger/>

> Not knowing what your document looks like, I can only guess at a
> solution... possibly
> 
>     $("#second_field").prop("disabled", true);

Or, much more efficient:

  document.getElementById("second_field").disabled = true;

See also:

<https://gist.github.com/chitsaou/3066411>
<http://youmightnotneedjquery.com/>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

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


Thread

trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect fugee279@gmail.com - 2015-11-29 20:23 -0800
  Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect Stefan Weiss <krewecherl@gmail.com> - 2015-11-30 09:43 +0100
    Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect fugee279@gmail.com - 2015-11-30 04:11 -0800
      Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect Stefan Weiss <krewecherl@gmail.com> - 2015-11-30 14:24 +0100
        Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect fugee279@gmail.com - 2015-11-30 11:06 -0800
        Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-11-30 22:25 +0100
    Re: trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-11-30 22:43 +0100

csiph-web