Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28926 > unrolled thread
| Started by | fugee279@gmail.com |
|---|---|
| First post | 2015-11-29 20:23 -0800 |
| Last post | 2015-11-30 22:43 +0100 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.lang.javascript
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
| From | fugee279@gmail.com |
|---|---|
| Date | 2015-11-29 20:23 -0800 |
| Subject | 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 |
| Message-ID | <72249e91-27c8-4895-ae4d-f4d974e1b85d@googlegroups.com> |
<script>
$(document).ready(function () {
$('#select_field').change(function(e)
{
if (e.target.value=='select_value') {e.second_field.disabled = true;}
})
})
</script>
[toc] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2015-11-30 09:43 +0100 |
| Message-ID | <n3h27k$52k$1@news.albasani.net> |
| In reply to | #28926 |
On 2015-11-30 05:23, fugee279@gmail.com wrote:
> <script>
> $(document).ready(function () {
> $('#select_field').change(function(e)
> {
> 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. Not knowing what your document
looks like, I can only guess at a solution... possibly
$("#second_field").prop("disabled", true);
- stefan
[toc] | [prev] | [next] | [standalone]
| From | fugee279@gmail.com |
|---|---|
| Date | 2015-11-30 04:11 -0800 |
| Message-ID | <647cdcc7-b9b8-40d4-acec-598dadd20c02@googlegroups.com> |
| In reply to | #28927 |
There's no error in the console This code doesn't work either The page loads ok, but the second_field never gets disabled
<script>
$(document).ready(function () {
$('#first_field').change(function(e)
{
if (e.target.value=('Fixed price') {$("#second_field").prop("disabled", true); }
})
})
</script>
[toc] | [prev] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2015-11-30 14:24 +0100 |
| Message-ID | <n3hilo$4up$1@news.albasani.net> |
| In reply to | #28928 |
On 2015-11-30 13:11, fugee279@gmail.com wrote:
> There's no error in the console This code doesn't work either The
> page loads ok, but the second_field never gets disabled
>
> <script>
> $(document).ready(function () {
> $('#first_field').change(function(e)
> {
> if (e.target.value=('Fixed price') {$("#second_field").prop("disabled", true); }
> })
> })
> </script>
I would be very surprised if this code didn't show at least one error
message in the console.
You're not likely to get a better remote diagnosis until you show more
of your document or post a link. (and fix the syntax error)
- stefan
[toc] | [prev] | [next] | [standalone]
| From | fugee279@gmail.com |
|---|---|
| Date | 2015-11-30 11:06 -0800 |
| Message-ID | <5c9f102b-aa69-4a23-b7ff-ff9772d97643@googlegroups.com> |
| In reply to | #28929 |
thanks, stefan, that was pretty big mistake i was making in firefox i went to tools->web developer->debugging and then i searched for "error" and there's nothing
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-11-30 22:25 +0100 |
| Message-ID | <4786816.k7Yo8ENYBU@PointedEars.de> |
| In reply to | #28929 |
Stefan Weiss wrote:
> On 2015-11-30 13:11, fugee279@gmail.com wrote:
>> There's no error in the console This code doesn't work either The
>> page loads ok, but the second_field never gets disabled
>>
>> <script>
>> $(document).ready(function () {
>> $('#first_field').change(function(e)
>> {
>> if (e.target.value=('Fixed price')
^ has to be =
>> {$("#second_field").prop("disabled", true); }
>> })
>> })
>> </script>
>
> I would be very surprised if this code didn't show at least one error
> message in the console.
It would show only one error message, a
> […] syntax error […]
as this code does not compile.
--
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.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-11-30 22:43 +0100 |
| Message-ID | <1653278.dNK5XENbKT@PointedEars.de> |
| In reply to | #28927 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web