lindm Posted January 16, 2010 Share Posted January 16, 2010 In a form it often seems a waste of space with both the id and name attribute for a field, since they often are the same: <input name="field" type="text" id="field" value="0" /> So far both have been necessary for a form submit and for instance if I also have javascript handling of the field. I have read that in xhtml id replaces name but can't get this to work. What would be nice is if the name attribute could be removed for a input field and when the form is submitted the id becomes part of the $_POST. Quote Link to comment Share on other sites More sharing options...
trq Posted January 16, 2010 Share Posted January 16, 2010 name attributes are the only way to reference an element once your form has been submitted. Quote Link to comment Share on other sites More sharing options...
AngelG107 Posted January 16, 2010 Share Posted January 16, 2010 Actually the id in an input field is not necessary even though you're using Javascript to refer to it, that could be done using : document.forms[0].fieldname.value = "Field Value"; You can remove the id, and simply refer to it like that in Javascript, and then in PHP,ASP, etc... you can refer to it with the name value. PS : forms is an array so the '0' is referring to the first form field in the HTML file. 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.