Jump to content

<input name OR id>


Recommended Posts


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

Link to comment
Share on other sites

  • 2 weeks later...

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.



Link to comment
Share on other sites

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>

   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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.