[Javascript] Dollar function for name=

Rees, Mark Mark.Rees at astrazeneca.com
Tue Jun 1 10:16:44 CDT 2010


Hello All,

Is there a method for finding a name="whatever" on a page similar to document.getElementById('whatever')?

For example suppose I have this form...


<form action="go.html" method="post">
 <input type="text" name="myname">
 <input type="text" name="mypass">
 <input type="submit" name="mysubmit" value="Login">
</form>


I would like to target name="myname" in a similar way that I can with getElementById()

Even if it takes a fair bit of code to do it it would be nice to have a 'dollar' type function for this.

When I use the term dollar function I am referring to the fairly ubiquitous convenience function for getElementById() found in the popular javascript library prototype.

Thanks,

Terry Riegel

--------------------------------
There is in prototype. See the docs, always a good starting point

http://api.prototypejs.org/language/dollardollar/

And use the CSS3 attribute selectors

http://www.css3.info/preview/attribute-selectors/

Obviously, the double dollar method returns an array of Elements rather than an Element, as attribute name/value pairs are not guaranteed to be unique. IDs of course are unique (in a valid document anyway)

--------------------------------------------------------------------------
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