[Javascript] Dollar function for name=

Rees, Mark Mark.Rees at astrazeneca.com
Wed Jun 2 09:44:09 CDT 2010


> Try this then, again from Prototype since that's what you're using
> 
> http://api.prototypejs.org/dom/element/writeattribute/
> 
> so once more:
> 
> $$('input[name="pizze"]').each(function(el){
>  	el.writeAttribute('value','sausage');
> });
> 
> Not quite as neat as jquery though

Ok I'll give it a whirl, but as I read it it doesn't appear to handle the logic with radio and checkboxes.

Given...

<input type="radio" name="pizze" value="Sausage">
<input type="radio" name="pizze" value="Pepperoni">
<input type="radio" name="pizze" value="Ham">



Wouldn't your code leave it looking like...

<input type="radio" name="pizze" value="Sausage">
<input type="radio" name="pizze" value="Sausage">
<input type="radio" name="pizze" value="Sausage">



What I would want it to do is leave it looking like...

<input type="radio" name="pizze" value="Sausage" checked="true">
<input type="radio" name="pizze" value="Pepperoni">
<input type="radio" name="pizze" value="Ham">



Thanks,

Terry

-------------------------------
I see, I think. Again the code is untested. 

//find all inputs which have the name of pizze and the value of Sausage
$$('input[name="pizze"][value="Sausage"]').each(function(el){
	//and write the "checked" attribute on each one
	el.writeAttribute('checked','checked');	
});

Read the docs and try some of this out for yourself. There are loads of examples out there. Here's one
http://alternateidea.com/blog/articles/2006/3/27/prototype-gets-attribute-selectors

--------------------------------------------------------------------------
AstraZeneca UK Limited is a company incorporated in England and Wales with registered number: 03674842 and a registered office at 15 Stanhope Gate, London W1K 1LN.
Confidentiality Notice: This message is private and may contain confidential, proprietary and legally privileged information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorised use or disclosure of the contents of this message is not permitted and may be unlawful.
Disclaimer: Email messages may be subject to delays, interception, non-delivery and unauthorised alterations. Therefore, information expressed in this message is not given or endorsed by AstraZeneca UK Limited unless otherwise notified by an authorised representative independent of this message. No contractual relationship is created by this message by any person unless specifically indicated by agreement in writing other than email.
Monitoring: AstraZeneca UK Limited may monitor email traffic data and content for the purposes of the prevention and detection of crime, ensuring the security of our computer systems and checking Compliance with our Code of Conduct and Policies.


More information about the Javascript mailing list