> -----Original Message-----
> From: Roland Tarver [mailto:[EMAIL PROTECTED]
> Sent: 28 May 2003 10:07
> 
> I've got a question about about naming html components (text fields, 
> select boxes etc) when submitting a form to a php page.
> First I tried identifying an element using the "id" attribute 
> and found 
> that it was not being posted to the php page. When I use the "name" 
> attribute it did get posted to the page?
> 
> I had a look on the w3c html spec and "name" takes precedence 
> over "id" 
> if used together but you should be able to use them 
> individually with no 
> problems.
> 
> When you submit a form with this select box, "country" will is not 
> submitted to the php page.
> <select *id*="country" onChange="alterForm();">
> <option value="one">one</option>
> <option value="two">two</option>
> </select>
> 
> 
> When you use this code, it works fine. "country"  gets 
> submitted to the 
> php page?
> <select *name*="country" onChange="alterForm();">
> <option value="one">one</option>
> <option value="two">two</option>
> </select>
> 
> Any thoughts?

This is according to the HTML 4.01 specification, which says:

   "When a form is submitted for processing, [...] controls have
    their name paired with their current value and these pairs
    are submitted with the form."

This also applies to XHTML 1.0 -- indeed, the XHTML 1.0 Strict DTD says that the name= 
attribute is *required* for all <input > types except submit and reset.

None of this is likely to change in the foreseeable future -- name= will always be the 
one to use for submitted form elements.

The id= attribute is for identifying a particular element uniquely within the [X]HTML 
document -- no two elements can have the same id= attribute.  Its most likely uses are 
for specifically targeted stylesheet formatting, or manipulating a specific element 
using a client-side technology such as JavaScript.  It is absolutely *not* a 
substitute for name= in form elements. 

Hope this clears things up a bit for you.

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to