"Thanks for that but like most things in the prototype documentation,
it
lacks the type of clarity that I can understand. "

Nice way to get help... "Your docs suck so just spoon feed me the
answer"

The answer to your initial approach is an issue with basic javascript
string behavior and was nailed on the head by both Johnathon and David

var myVariableValue = 3;

var mySelector = "input[type=radio][name='type']
[value='myVariableValue']";

In the above expression the value of myVariableValue isn't evaluated,
its literally written into the string as is, hence its not the value 3
its the string value "myVariableValue"

Hope you like puree'd corn template

var myTemplate = new Template("input[type=#{type}][name='#{name}']
[value='#{value}']");
var dto = { type : 'radio', name : 'type', value : '3' };

var selector = myTemplate.evaluate(dto);




On Sep 25, 6:28 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> The fundamental thing you need to do is _simplify_, divide and
> conquer. Is it the XML stuff that isn't working, or is it the radio
> button stuff that isn't working? Walk through with a debugger, etc.
>
> The `$$` of this is not the problem barring some strange thing, you'll
> need to look elsewhere.
>
> -- T.J.
>
> On Sep 25, 4:16 pm, Phil Petree <phil.pet...@gmail.com> wrote:
>
>
>
> > Morning TJ!
>
> > I know it SHOULD work... I'm just saying it didnt.
>
> > works:
> >     // set radio button for type
> >     selectThis = {selectID: 'type', selectValue:
> > transport.responseXML.getElementsByTagName('type')[0].firstChild.nodeValue} 
> > ;
>
> >     $$(radioTemplate.evaluate(selectThis))[0].writeAttribute("checked",
> > "checked");
> >  didn't work:
> >     var selectThis
> > = 
> > transport.responseXML.getElementsByTagName('type')[0].firstChild.nodeValue;
> >     $$("input[type=radio][name='type'][value='" + selectThis +
> > "']").writeAttribute("checked", "checked");
>
> > ALSO:
>
> > This works:
> >     selectThis = {matchString:
> > transport.responseXML.getElementsByTagName('state')[0].firstChild.nodeValue 
> > };
>
> >     $$('select#ajstate option').each(function(o){
> >       if(o.value == selectTemplate.evaluate(selectThis)){o.selected =
> > true;$break;}
> >     });
>
> > But moving it into a function doesn't:
> >     setSelect('ajState',
> > transport.responseXML.getElementsByTagName('state')[0].firstChild.nodeValue 
> > );
> > function setSelect(strID, strValue)
> > {
> >   var selectIDTemplate = new Template('#{matchID}');
> >   var selectTemplate = new Template('#{matchString}');
> >   var selectThis;
> >   var selectID;
>
> >   selectID = {matchID: strID};
> >   selectThis = {matchString: strValue };
> >   $$('select#selectIDTemplate.evaluate(selectID) option').each(function(o){
> >     if(o.value == selectTemplate.evaluate(selectThis)){o.selected =
> > true;$break;}
> >   });}
>
> > I think I am either daft or extremely tired! LOL
> > On Sat, Sep 25, 2010 at 10:34 AM, T.J. Crowder 
> > <t...@crowdersoftware.com>wrote:
>
> > > Hi,
>
> > > > David, although your suggestion doesn't throw any errors, it doesnt work
> > > > either... kinda wierd as I thought it would...
>
> > > It does work, barring there being something wrong somewhere else:
> > >http://jsbin.com/elota3
>
> > > The problem with your original code was as as Jonathan said, you were
> > > passing the string "input[type=radio][name='type'][value=selectThis]"
> > > into $$ as the selector. David's suggestion fixes that by using the
> > > *value* of selectThis rather the actual text "selectThis". As the live
> > > example above shows, that works.
>
> > > FWIW,
> > > --
> > > T.J. Crowder
> > > Independent Software Engineer
> > > tj / crowder software / com
> > > www / crowder software / com
>
> > > On Sep 25, 2:21 pm, Phil Petree <phil.pet...@gmail.com> wrote:
> > > > David, although your suggestion doesn't throw any errors, it doesnt work
> > > > either... kinda wierd as I thought it would... and it would have been
> > > MUCH
> > > > simpler to implement too!
>
> > > > On Sat, Sep 25, 2010 at 8:57 AM, David Behler <d.beh...@gmail.com>
> > > wrote:
> > > > > What about this:
>
> > > > > $$("input[type=radio][name='type'][value='" + selectThis + "']")
>
> > > > > ?
>
> > > > > Am 25.09.2010 14:41, schrieb Phil Petree:
>
> > > > > Jonathan,
>
> > > > > Thanks for that but like most things in the prototype documentation, 
> > > > > it
> > > > > lacks the type of clarity that I can understand.
>
> > > > > IOW, I can read the documentation, scratch my head and say huh? I 
> > > > > leave
> > > > > that documentation thinking "this might be what I need but have no 
> > > > > clue
> > > as
> > > > > to how to implement that to solve my problem."
>
> > > > > Which is exactly what happened here... OK, I need to use templates to
> > > > > somehow sprintf the string constant into a direct value but huh?
>
> > > > > On Sat, Sep 25, 2010 at 7:59 AM, Jonathan Rosenberg <
> > > j...@tabbysplace.org>wrote:
>
> > > > >>  You're passing a string constant to $$
>
> > > > >>     "input[type=radio][name='type'][value=selectThis]")
>
> > > > >> 'selectThis' will not be evaluated, as you seem to be expecting.  
> > > > >> Have
> > > a
> > > > >> loook at Tenplate to do what you want:
>
> > > > >>    http://www.prototypejs.org/api/template
>
> > > > >> --
> > > > >> Jonathan Rosenberg
> > > > >> Founder & Executive Director
> > > > >> Tabby's Place
> > > > >>http://www.tabbysplace.org
>
> > > > >>  -----Original Message-----
> > > > >> *From:* prototype-scriptaculous@googlegroups.com [mailto:
> > > > >> prototype-scriptacul...@googlegroups.com] *On Behalf Of *Phil Petree
> > > > >> *Sent:* Saturday, September 25, 2010 7:46 AM
> > > > >> *To:* prototype-scriptaculous@googlegroups.com
> > > > >> *Subject:* [Proto-Scripty] Variables in $$() ?????
>
> > > > >> I've hit this in two seperate places and not exactly sure why...
> > > > >> (I think its the 18 hour days, 7 days a week... <g>)
>
> > > > >> If "value" is hard set with '3' the following works:
>
> > > $$("input[type=radio][name='type'][value='3']")[0].writeAttribute("checked"
> > > ,
> > > > >> "checked");
> > > > >> However, if we use a variable (selectThis) and assign it "3" it does
> > > not
> > > > >> work.
> > > > >> var selectThis;
> > > > >> selectThis = '3';
>
> > > $$("input[type=radio][name='type'][value=selectThis]")[0].writeAttribute("c
> > > hecked",
> > > > >> "checked");
>
> > > > >> Type casting doesn't work either:
> > > > >> var selectThis;
> > > > >> selectThis = String('3');
>
> > > $$("input[type=radio][name='type'][value=selectThis]")[0].writeAttribute("c
> > > hecked",
> > > > >> "checked");
>
> > > > >> I'm having the same problem here too (compare o.value== 'GA' and the
> > > > >> select gets set to GA):
> > > > >> selectThis = 'GA'
> > > > >> $$('select#ajstate option').each(function(o){
> > > > >>     if(o.value==selectThis){o.selected = true;$break;}
> > > > >> });
>
> > > > >> What am I missing here?
> > > > >> --
> > > > >> You received this message because you are subscribed to the Google
> > > Groups
> > > > >> "Prototype & script.aculo.us" group.
> > > > >> To post to this group, send email to
> > > > >> prototype-scriptacul...@googlegroups.com.
> > > > >> To unsubscribe from this group, send email to
> > > > >> prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculou
> > > > >>  s%2bunsubscr...@googlegroups.com><prototype-scriptaculou
> > > s%2bunsubscr...@googlegroups.com <s%252bunsubscr...@googlegroups.com>>
> > > > >> .
> > > > >> For more options, visit this group at
> > > > >>http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
> > > > >> --
> > > > >> You received this message because you are subscribed to the Google
> > > Groups
> > > > >> "Prototype & script.aculo.us" group.
> > > > >> To post to this group, send email to
> > > > >> prototype-scriptacul...@googlegroups.com.
> > > > >> To unsubscribe from this group, send email to
> > > > >> prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculou
> > > > >>  s%2bunsubscr...@googlegroups.com><prototype-scriptaculou
> > > s%2bunsubscr...@googlegroups.com <s%252bunsubscr...@googlegroups.com>>
> > > > >> .
> > > > >> For more options, visit this group at
> > > > >>http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Prototype & script.aculo.us" group.
> > > > > To post to this group, send email to
> > > > > prototype-scriptacul...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculou
> > > > >  s%2bunsubscr...@googlegroups.com>
> > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
> > > > >   --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Prototype & script.aculo.us" group.
> > > > > To post to this group, send email to
> > > > > prototype-scriptacul...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculou
> > > > >  s%2bunsubscr...@googlegroups.com><prototype-scriptaculou
> > > s%2bunsubscr...@googlegroups.com <s%252bunsubscr...@googlegroups.com>>
> > >  > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Prototype & script.aculo.us" group.
> > > To post to this group, send email to
> > > prototype-scriptacul...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculou
> > >  s%2bunsubscr...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to