Bman900 Posted November 19, 2009 Share Posted November 19, 2009 Hi there, I am still learning here and I just have a quick question about this code here: <html> <input type="text" id="firstname" name="firstname" /> </html> What is the point of the "id" tag? I have been watching some tutorials and they seem to just skip that and only set the type and use the name attribute. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
haku Posted November 19, 2009 Share Posted November 19, 2009 The ID and NAME do different things. ID is for two main things. The first is for styling the tag using CSS. Ids are only allowed to be used once per page, so if you need to target a specific element for styling, you can give it an ID, and style that element and only that element (there are also classes which can be used on multiple elements in a page, and allow for styling all of them at once). The other use for IDs is in Javascript. Basically it does the same thing as CSS - it allows a javascript function to target that element and only that element, and do something to it. The NAME attribute is completely different. When you are creating form element and you submit them, the script you submit them to has to know what values you submitted. What happens is that the submitted value is tied to the NAME attribute. So if you enter 'haku' into the input you put above, the value of 'haku' as accessible to the script using the NAME 'firstname': $first_name = $_POST['firstname']; The code above (which is PHP code) creates a variable, which is like a container, called $first_name, then it puts a value into that variable (container). The value it puts in is the value that was in the <input> tag with a NAME of 'firstname'. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.