Hello all, I''m new to prototype and javascript isn''t my strong point. I''m trying to get a simple test script to work, which is turning out to be a little harder than I thought. I have a bunch of fields that I need to be able to switch on and off using one of a few hashes. In the example below I''m trying to get one to work. The problem occurs when I try to use the hash key to get a document id. Is there a way to get a document id with a key from the hash below? Javascript: var my_inputs = { status : 1 name : 0; }; $H(my_inputs).each( function(inp) { if ( inp.value == 1 ) { $(inp.key).show; } else { $(inp.key).hide; } }); HTML: <div id="status" class="frow"> <label for="status">Status:</label> <select name="status" size="1"> <option value="1">Registered</option> <option value="2">Wait Listed</option> <option value="3">Cancelled</option> </select> </div> <div id="name" class="frow"> <label for="name">Name:</label> <select name="name" size="1"> <option value="1">Bob</option> <option value="2">Joe</option> <option value="3">Phil</option> </select> </div> Any help would be greatly appreciated. Thanks, Tatnall --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, posted with an error my_inputs should be: var my_inputs = { status : 1, name : 0 }; --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I haven''t tested this but try this: $H(my_inputs).each( function(inp) { if ( inp.value == 1 ) { $(inp.key).show(); } else { $(inp.key).hide(); } }); The only thing I changed was putting () after show and hide. On 11/22/06, BT <btatnall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Sorry, posted with an error my_inputs should be: > > var my_inputs = { > status : 1, > name : 0 > }; > > > > >-- DCRails.com || Making the Metrorail fun! http://www.captureimportant.info || Sidewalk || Bring People to You --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Schlueter wrote:> I haven''t tested this but try this: > $H(my_inputs).each( function(inp) { > if ( inp.value == 1 ) { > $(inp.key).show(); > } else { > $(inp.key).hide(); > } > }); > > > The only thing I changed was putting () after show and hide. >No dice. I''m still getting the same error. $(inp.key) has no properties. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
BT wrote:> No dice. I''m still getting the same error. > > $(inp.key) has no properties.Are you per-chance, trying to use the HTML element before it exists? Your JS code that uses an element must come after the HTML for that element. -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Peters wrote:> BT wrote: > > > No dice. I''m still getting the same error. > > > > $(inp.key) has no properties. > > Are you per-chance, trying to use the HTML element before it exists? Your JS > code that uses an element must come after the HTML for that element. > > -- > Michael Peters > Developer > Plus Three, LPI certainly was, which brought me to another error saying the function wasn''t available and I rewrote $(inp.key).hide.() to Element.hide(inp.key) and now it works. Thank you! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
BT wrote:> Hello all, > > I''m new to prototype and javascript isn''t my strong point.It is easier to help if you explain what you expect the script to do and what it actually does do, along with any error messages. [...]> > <div id="status" class="frow"> > <label for="status">Status:</label>For the record, the value of a label''s for attribute must be an element ID, not a NAME. Some browsers only associate the label with an element if it is inside the label: <label for="status">Status:<select id="status" name="status" size="1"></label>> > <select name="status" size="1"> > <option value="1">Registered</option> > <option value="2">Wait Listed</option> > <option value="3">Cancelled</option> > </select> > </div> > > <div id="name" class="frow"> > <label for="name">Name:</label> > <select name="name" size="1">You shouldn''t give an element''s name attribute a value of "name", if it''s in a form, it will mask access to the form''s name attribute. Try: <form name="formA" action=""> <div> <input name="name" type="button" value="Show form name" onclick=" alert( this.form.name ); "> </div> </form> -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey there, This post FYI, clearing up a few normative issues. RobG a écrit :> For the record, the value of a label''s for attribute must be an element > ID, not a NAME. Some browsers only associate the label with an element > if it is inside the label:Actually, this is normative [1]. Do you have examples of v4+ browsers that *don''t*? I never looked into it.> <label for="status">Status:<select id="status" > name="status" size="1"></label>This isn''t valid XHTML, though: your <select> element isn''t closed. From a semantical standpoint, it''s also empty, but one could imagine it''s filled in by AJAX/DOM means.> You shouldn''t give an element''s name attribute a value of "name", if > it''s in a form, it will mask access to the form''s name attribute. Try:Indeed, which is yet one example of how providing extensions to the normative DOM is a mess (namely, ''.'' access to form elements by their name).> <form name="formA" action=""> > <div> > <input name="name" type="button" value="Show form name" > onclick=" alert( this.form.name ); "> > </div> > </form>Empty actions are also a convention, not a normative issue [2]. It''s a common misuse to have empty or "#" actions, when proper code would explicitely write the current URL in there. Finally, form elements have no standard ''form'' attribute referencing their container form [3]. You should know the form''s ID and use it, or walk up the DOM until you find a form (something easily done with Prototype''s Element.up method). [1] http://www.w3.org/TR/html401/interact/forms.html#adef-for [2] http://www.w3.org/TR/html401/interact/forms.html#adef-action [3] http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-6043025 -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/23/06, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> RobG a écrit : > > For the record, the value of a label''s for attribute must be an element > > ID, not a NAME. Some browsers only associate the label with an element > > if it is inside the label: > > Actually, this is normative [1]. Do you have examples of v4+ browsers > that *don''t*? I never looked into it.I only know of an IE bug where funnily enough <label>Status: <input ...></label> does not behave like expected. The label still needs a "for" attribute, but it should not need it.> Finally, form elements have no standard ''form'' attribute referencing > their container form [3]. > [3] http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-6043025The reference you gave says: readonly attribute HTMLFormElement form; --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve wrote:> Hey there, > > This post FYI, clearing up a few normative issues.Let''s see - normative: establishing, relating to or deriving from a standard or norm. (Oxford American Dictionary).> > RobG a écrit : > > For the record, the value of a label''s for attribute must be an element > > ID, not a NAME. Some browsers only associate the label with an element > > if it is inside the label: > > Actually, this is normative [1].I don''t know what you are referring to. Labels can either enclose the element in question, or have an appropriate value for their for attribute, or both.> Do you have examples of v4+ browsers > that *don''t*? I never looked into it.Don''t what? Don''t correctly associate a label with an element that is part if the label''s content if there is no for attribute? I apologise for the confusion, my original statement was not very clear about that. All versions of IE up to version 6 at least will fail, I haven''t tested version 7. Try it, put this in IE: <label>A label<input type="checkbox"></label> Click on the label, the checkbox isn''t checked. Add a for attribute and matching id and behold, it works.> > > <label for="status">Status:<select id="status" > > name="status" size="1"></label> > > This isn''t valid XHTML, though: your <select> element isn''t closed. From > a semantical standpoint, it''s also empty, but one could imagine it''s > filled in by AJAX/DOM means.Who mentioned XHTML? Yes, the unclosed and empty select is invalid HTML so I guess I''ve been hoist with my own petard there, try: <label for="status">Status:<select id="status" name="status" size="1"><option></select></label>> > > You shouldn''t give an element''s name attribute a value of "name", if > > it''s in a form, it will mask access to the form''s name attribute. Try: > > Indeed, which is yet one example of how providing extensions to the > normative DOM is a mess (namely, ''.'' access to form elements by their name).The use of a dot property accessor is irrelevant, it fails whether you use ''.name'', [''name''] or (in IE) getAttribute(''name'') [1]. The issue is caused by resolving identifiers against the named properties of the form object, where the names of all the form controls are added as properties. An HTMLFormElement is *required* by the specification to make named form controls availble by their name as a component of the ECMAScript Language binding (noting that the DOM form object has an elements attribute that is a collection of all the form''s controls and implements the HTMLCollection interface): "Functions of objects that implement the HTMLCollection interface: ... "namedItem(name) "This function returns an object that implements the Node interface." <URL: http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>> > > <form name="formA" action=""> > > <div> > > <input name="name" type="button" value="Show form name" > > onclick=" alert( this.form.name ); "> > > </div> > > </form> > > Empty actions are also a convention, not a normative issue [2]. It''s a > common misuse to have empty or "#" actions, when proper code would > explicitely write the current URL in there.Let''s see what the spec says: "action = uri [CT] "This attribute specifies a form processing agent. User agent behavior for a value other than an HTTP URI is undefined." So an empty action attribute isn''t invalid, the spec just doesn''t say what a UA should do with it. Do you know of a browser that can''t cope with it? The W3C HTML validator is happy with it (while that isn''t proof of conformance, it''s a pretty good start). According to RFC 2396: "A URI reference that does not contain a URI is a reference to the current document." RFC 2396, "Uniform Resource Identifiers (URI): Generic Syntax", <URL: http://www.ietf.org/rfc/rfc2396.txt > How is that not normative?> > Finally, form elements have no standard ''form'' attribute referencing > their container form [3].That is completely wrong. Strictly speaking, you are correct that a form element doesn''t have form attribute, however I think you really meant form controls - and I think that is what you meant by the expression "form element". A form element is a form element. Certain elements (input, select, textarea, etc.) contained within a form and that have a suitable name attribute become form controls. In a conforming DOM, form controls have a form attribute that is a reference to the form element containing the control - read your own reference.> You should know the form''s ID and use it, or > walk up the DOM until you find a form (something easily done with > Prototype''s Element.up method).Considering the above, using the control''s form attribute is much simpler, much faster and doesn''t require the form to have an ID. Your logic here doesn''t make sense at all. 1. It "works" in Firefox, but probably only by coincidence. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- Bug? IE, getElementsByClassName and "length"
- Serializing non-ascii characters
- A new JavaScript Framework based on Prototype and Scriptaculous : Archetype
- Form.serialize: correctness and speed
- inheriting static/class methods with new prototype.js class creation