dotkpay Posted October 17, 2011 Share Posted October 17, 2011 Hello, What is the difference between the input attributes of 'name' and 'id'. As in when is 'name' used to define an <input> field and when is 'id' used. $_POST or $_GET globals are used to access the 'name' attribute by a php processing script, how do you access the 'id' attribute from a php script? Thanks in advance Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 17, 2011 Share Posted October 17, 2011 if you are using forms, PHP will get the variable from the name. the ID are usually used by jaavscript. Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted October 27, 2011 Share Posted October 27, 2011 Yeah as per above post. You could access ID element in php through ajax by extracting an element's ID (using jquery) and posting it to your php script as a variable. But I can't really see why you'd want to do that You can also access an element's name via jquery but the more usual way is to use IDs. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 27, 2011 Share Posted October 27, 2011 since you asked how to access the id attribute of an element, i'll give an example.. in the example I will show how to grab a filed value using jquery (javascript framework) <form action='test.php' method='POST' onsubmit='testFunc'><input type='text' value'default Value' id='text_input' /><input type='submit' value='submit' /></form> testFunc(){ var input_val input_val = $("#text_input").val(); if(input_val != "default Value"){ //probably do some AJAX here } return false; //stops the forms default action } now you will also want to handle the form using PHP as well, just in case the user does not have javascript enabled, thus why I included the form tags and filled in the necessary information needed for PHP to handle it 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.