Get the value of clicked text box from array of text boxes using PHP -
i want text box value selected array of text boxes.. code this:
here displaying data on browser db..
<?php foreach($datadecoded['categories'] $key => $value) { ?> <tr> <td><?php echo $value['categoryname'];?></td> <td> <input type="text" name="categoryid[]" id="categoryid" value="<?php echo $value['categoryid']?>"> <input type="text" name="categoryname[]" id="categoryname" value="<?php echo $value['categoryname']?>"> <input type="submit" name="create" id="create" value="create"> </td> </tr> <?php } ?> the data displayed like:
categoryid1 categoryname1 <create button> categoryid2 categoryname2 <create button> categoryid3 categoryname3 <create button> , on this.. now, suppose when click on create button of categoryname2, want categoryid , categoryname of categoryname2..
am using code:
if(isset($_post['create']) && $_post['create']=="create") { $cat_id[]=$_post['categoryid']; $cat_name[]=$_post['categoryname']; } but this, getting categoryid , categoryname array.. how selected textbox value..
i want using php , not javascript / jquery... bit new php... can me / give me suggestion how it...
thanks in advance.
wrap each 1 in own form:
<td> <form method="post" action="somepage.php"> <input type="text" name="categoryid" value="<?php echo $value['categoryid']?>"> <input type="text" name="categoryname" value="<?php echo $value['categoryname']?>"> <input type="submit" name="create" value="create"> </form> </td> since content being posted in case these 2 values, that's entire scope of single form post. each 1 logically/semantically own form. (there's no rule says page can have 1 form. unless you're ever using asp.net webforms, lie.)
note removed id attributes. multiple elements can't have same id, that's invalid html , behavior result becomes undefined.
Comments
Post a Comment