Jump to content

<input name OR id>


dotkpay

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/249264--/
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
https://forums.phpfreaks.com/topic/249264--/#findComment-1282636
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>

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

Link to comment
https://forums.phpfreaks.com/topic/249264--/#findComment-1282644
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.