From: S.T. on
On 3/31/2010 1:57 PM, David Mark wrote:
> I don't think it takes an endless "rant" to get across what Richard has
> already said: it is *insane* to just jQuery to read and write form
> control values.

Richard sent the poster off to, in the true spirit of the cljs FAQ, a
verbose ~8 page technical analysis of the subject - albeit, after
answering the OP's question. The vastly overcomplicated 'resource' is an
excellent example of why projects such as jQuery are so popular and why
it's use for even simple functionality is hardly "insane". At worst,
"unnecessary".
From: David Mark on
S.T. wrote:
> On 3/31/2010 1:57 PM, David Mark wrote:
>> I don't think it takes an endless "rant" to get across what Richard has
>> already said: it is *insane* to just jQuery to read and write form
>> control values.
>
> Richard sent the poster off to, in the true spirit of the cljs FAQ, a
> verbose ~8 page technical analysis of the subject - albeit, after
> answering the OP's question.

Reading and writing value properties shouldn't require reading anything.
It's as simple to do with the DOM as with jQuery (simpler even) and it
won't have the incompatibility burdens imposed by jQuery. It's a
no-brainer.

> The vastly overcomplicated 'resource' is an
> excellent example of why projects such as jQuery are so popular and why
> it's use for even simple functionality is hardly "insane". At worst,
> "unnecessary".

It's insane if you understand how badly the queries (among many other
things) work in jQuery. Beginners see them as magic black boxes, but
they vary from one browser (and jQuery version) to the next, even for
simple queries. It's *complete* insanity to rely on such a concoction
when the form - elements - collections are readily available. And oh
BTW, you can save 70K+ and future, incompatible upgrade headaches as
well. The trouble is that the average Web developer doesn't understand
these issues at all. That's why the thing has oozed its way all over
the Web.
From: Garrett Smith on
monkeys paw wrote:
> I'm struggling to change the value of a hidden
> field based on an "click" event. Here's what i
> got, you guys know how to do this correctly?
>

It sounds like a simple task.

> The toggle function should swap images, which
> it does correctly. However, there is a hidden
> field named print_summary. I want the "value"
> of the hidden field to toggle as the images
> do, between on and off. I've tried a few things,
> here is the latest. If you know how to do
> this i'm all ears fellas...
>

First off, use standards mode HTML. Use a doctype that will trigger
standards mode to do this. Do that, and then run the code through
validator.w3.org. This is an important process that can reveal errors
and problems in the code, and will help ensure more consistent behavior
across browsers.

> .
> <html>
> <head>
> <title>State Net | Budget Item Schedule</title>
> <SCRIPT LANGUAGE='JavaScript1.2' type='text/javascript'
> SRC='/js/jquery-1.3.2.min.js'></SCRIPT>

To simplify the problem, lets remove that.

> <script type="text/javascript">
> $(document).ready(function(){
> $("#summ_on").hide(0);
> $("#summ_button").toggle(function(){
> $("#summ_on").show('slow');
> $("#summ_off").hide('slow');
> $("#summ_value").value = "ON"
> $("input").filter("summ_value").value = "ON"
^
Is that an element selector or did you forget "#"?

> alert($("input").filter("summ_value").text)
> }, function() {
> $("#summ_on").hide('slow');
> $("#summ_off").show('slow');
> $("input").filter("summ_value").value = "OFF"
> alert($("input").filter("summ_value").text)
> });
> });
> </script>
> </head>
>

I noticed that you are performing queries and calling the `filter`
method repeatedly.

Not only are you using an element selector as "summ_value" and not an ID
selector as "#summ_value", but you do it again and again. I think that
is a mistake. Instead, you should just use document.getElementById.

If you are trying to learn how to program, then you ought to be writing
your own functions and not using a library. Example program outline:

var isButtonDepressed;

function buttonClickHandler(ev) {
if(isButtonDepressed) {
setDefaultState();
} else {
setDepressedState();
}
}

myButton.onclick = buttonClickHandler;

You'll need to define `setDefaultState` and `setDepressedState` to make
it work. If those functions need access to the button element, that can
be passed in from `buttonClickHandler` as `this`.

Problems with that code is there are all globals used. That can be fixed
by wrapping the whole thing in a closure, or function.
<http://jibbering.com/faq/#scope>

The assignment to `onclick` replaces whatever value existed previously.
Writing an event registry is not a simple task, so I won't go into it here.

> <body bgcolor="white" align="left">
>
Don't forget to validate!
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: RobG on
On Apr 1, 8:35 am, "S.T." <a...(a)anon.com> wrote:
> On 3/31/2010 1:57 PM, David Mark wrote:
>
> > I don't think it takes an endless "rant" to get across what Richard has
> > already said: it is *insane* to just jQuery to read and write form
> > control values.
>
> Richard sent the poster off to, in the true spirit of the cljs FAQ, a
> verbose ~8 page technical analysis of the subject - albeit, after
> answering the OP's question.

Richard first concisely and thoroughly answered the OPs question[1],
then provided a link to a resource that provides more general help
regarding access to form controls. The thinly veiled criticism in your
response seems to find fault with that.

Perhaps you'd rather the OP posted in the jQuery "Getting started"
forum, where the chance of getting any answer at all is little better
than 50/50 and the chance of getting an accurate, comprehensive answer
such as that offered by Richard is very nearly zero.


> The vastly overcomplicated 'resource' is an
> excellent example of why projects such as jQuery are so popular

By comparison, the simplistic jQuery documentation is more concise
mostly because it is not only inaccurate, but incomplete. It includes
gems like:

"In the case of <select multiple="multiple"> elements,
the .val() method returns an array containing each
selected option."

Does val() really return (references to) elements, or their values?
Where is the explanation of the handling of the value attribute and
text content for option elements? Where is the explanation of values
returned for radio button groups (which, presumably, are returned as
an array)? Where are the expected results from the (very minimal)
examples?

Is keeping users ignorant and reliant on jQuery a deliberate strategy,
or is it just a fortunate consequence of these shortcomings?

Instead of criticising the FAQ documentation, your time might be
better spent learning from it.

1. <URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/16f174defb56f60a#
>


--
Rob
From: S.T. on
On 3/31/2010 9:16 PM, RobG wrote:
> On Apr 1, 8:35 am, "S.T."<a...(a)anon.com> wrote:
>> On 3/31/2010 1:57 PM, David Mark wrote:
>>
>>> I don't think it takes an endless "rant" to get across what Richard has
>>> already said: it is *insane* to just jQuery to read and write form
>>> control values.
>>
>> Richard sent the poster off to, in the true spirit of the cljs FAQ, a
>> verbose ~8 page technical analysis of the subject - albeit, after
>> answering the OP's question.
>
> Richard first concisely and thoroughly answered the OPs question[1],
> then provided a link to a resource that provides more general help
> regarding access to form controls. The thinly veiled criticism in your
> response seems to find fault with that.
>
> Perhaps you'd rather the OP posted in the jQuery "Getting started"
> forum, where the chance of getting any answer at all is little better
> than 50/50 and the chance of getting an accurate, comprehensive answer
> such as that offered by Richard is very nearly zero.

I didn't have a problem with Richard's answer of the OP's question. I
even mentioned he answered the question. Perhaps I should have added he
answered it well, which he did.

However then adding it's "insane" to use jQuery for this and steering
him/her to an 8-page technical thesis as the preferred alternative is
quite a leap of faith.

>
>> The vastly overcomplicated 'resource' is an
>> excellent example of why projects such as jQuery are so popular
>
> By comparison, the simplistic jQuery documentation is more concise
> mostly because it is not only inaccurate, but incomplete. It includes
> gems like:
>
> "In the case of<select multiple="multiple"> elements,
> the .val() method returns an array containing each
> selected option."
>
> Does val() really return (references to) elements, or their values?

Really? The method's name doesn't provide a hint?

> Where is the explanation of the handling of the value attribute and
> text content for option elements?

Isn't that more an HTML spec? If an option doesn't have a value
attribute, it's value is the contents of the option.

.... and on and on. The jQuery docs aren't perfect but they're pretty
good. Trying to document every possible contingency leads to something
like the cljs FAQ, which is a clear example of "too many cooks in the
kitchen" and complete overkill for the casual DOM scripter.