Wrox Programmer Forums
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2005, 06:34 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default ID

<input type="text" name="comp_name" id="comp_name">
whats the ID used for here?

Picco


www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old February 8th, 2005, 07:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
Default

http://www.w3.org/TR/html401/struct/global.html#adef-id

(o<
//\ =^..^=
 
Old February 8th, 2005, 10:11 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

ID is the one which you can refer in Javascript.


Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 8th, 2005, 12:04 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

In addition to the specification document provided by meow.

An id is a unique name. It can be used in a number of different contexts, but it is used to uniquely identify an element in a document. This identification can serve serveral purposes.

* It can provide an anchor to link to within a document.
* It can allow the element to be styled via CSS.
* It can allow the element to be accessed via the DOM (Document Object Model), through Javascript.

Via the first and second examples the id is always referenced with a pound sign (or hash mark, whichever term you prefer).

Say you want to link to a specific location within a document. This is done by giving the element you want to link to an id name.

<p>Some text here</p>
<p>Some more text</p>
<p id='anchorhere'>Yet more text</p>

Now imagine that each of these paragraphs are extrordinarily lengthy. You can link to a specific paragraph by writing up a hyperlink, (assuming this page is called some_page.html) http://www.example.com/some_page.html#anchorhere. With this link the page will automatically scroll to the third paragraph.

If you also want to add some styles to that third paragraph, to make it stand out from the others you do that via the id selector in CSS.

p#anchorhere {
   background: lightyellow;
   padding: 10px;
   border: 1px solid black;
}

Now its been styled as well, note that both methods make use of the hash mark.

In an input form the id takes on an additional meaning. Consider this example.

<input type='text' name='some_name' id='somename' />

I suppose that technically you should avoid underscores in id names, as support is bad for them in older browsers, this is because of CSS. But nothing is really stopping you from making the name and the id the same, as in...

<input type='text' name='some_name' id='some_name' value='some value' />

Modern browsers understand that just fine.

Now an additional element can be introduced.
<label for='some_name'>Some name:</label> the for attribute links this label directly to the <input /> element with a some_name id. When you put this in a page and click on the <label> element, you'll see that the <input> gains focus.

You might wonder why have an id attribute when there is a name attribute, the reasoning behind this is the id name should be unique, it should not be repeated and it has multiple applications. The name attribute can be repeated. As far as the specifications are concerned, IIRC, the name attribute is deprecated for everything with the exception of form input elements.

Finally, (at least as much as I can think of so far), you can use the id name in javascript.

<script type='text/javascript'>
    alert(document.getElementById('some_name').value);
</script>

This snip of javascript will alert the current value of the 'some_name' <input> element.

HTH!


Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old February 8th, 2005, 01:05 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks 4 that

www.crmpicco.co.uk
 
Old February 10th, 2005, 11:50 AM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

oh great info on ids :-)
arigato as the japanese like to say so often.

----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq





Similar Threads
Thread Thread Starter Forum Replies Last Post
'this.ID = id;' in class construction holf BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 October 6th, 2006 10:58 AM
session id rbojja J2EE 2 February 13th, 2006 05:48 AM
session id rbojja J2EE 1 February 11th, 2006 01:22 PM
why not index.asp?id=1 can be www.myweb.com/?id=1 BurhanKhan Classic ASP Professional 11 September 6th, 2004 02:06 PM
Record ID sinner Classic ASP Databases 12 February 28th, 2004 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.