开发者

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
}


ids are not submitted with POST data. It's not possible to get their value back.
Use different names 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜