php get an element's id after submit
<input type = 'text' name = 'name_'<?php echo $rownum'?> id = <?php echo $category_id ?> /> $rownum++;
After submit I iterate through the text fields. While doing that I want to check whether this text's id is in an array. So for that I want to get the id o开发者_运维问答f the text field. How is it possible?
IDs are not accessible with the post. Change it and make it easy to handle
<input type = 'text' name = 'name[<?php echo $category_id ?>]' id = <?php echo $category_id ?> /> $rownum++;
Now subimit it and you have everything you want in $_POST
.
This element will be accessible like this
$_POST['name']
will be an array iterate through it
foreach ($_POST['name'] as $key => $value)
{
echo $key; // $key is the id you want
echo $value; //$value is the value set for this id
}
id
s are not submitted with POST data. It's not possible to get their value back.
Use different name
s that give you the information you need, since only they are submitted.
You would have to specifically pass that value into php. Once a value is sent out the the browser as HTML php has no more control over it. So when it gets resubmitted PHP only 'knows' whats handed to it. In this case it 'know' the name of the input and the value of the input.
精彩评论