1

how to get the selected textbox id generated in while loop for updating the field as in phpmyadmin

 <?php
    while($fet=mysql_fetch_assoc($sql1))
    {
        ?>
        <tr>
        <td><input type=text id='hello' name='hello' data-id="<?php echo  $fet['username']?>"     onchange='loadXMLDoc(this);' value=<?php echo $fet['username']?>>
       <td><input type=text id='uid' name='uid' onchange='loadXMLDoc(this).' value=<?php echo  $fet['id']?>>
       </tr>
       <?php 
        }
  ?>
3
  • 1
    i didn't understand your question you want get the val of a multiple checkbox ? or generate a dinaimiq id in the php? Commented Mar 8, 2014 at 4:53
  • I want to generate dynamic id for textbox Commented Mar 8, 2014 at 4:56
  • heres all the documentation about uniqid php.net/manual/pt_BR/function.uniqid.php Commented Mar 8, 2014 at 5:14

3 Answers 3

2

Just append i and increment it till your while loop goes on..

<?php
    $i=1;
    while($fet=mysql_fetch_assoc($sql1))
    {
       echo '
        <tr>
        <td>
          <input type="text" id="hello'.$i.'" name="hello'.$i.'" data-id="'.$fet['username'].'" onchange="loadXMLDoc(this.value,'.$i.')" value='.$fet['username'].' >
</td>           
       </tr>';
       here write ur code for other fields

         $i++;
    }
 ?>

<script> 
function loadXMLDoc(a,i) 
{ var d= document.getElementById("hello"+i).value; } 
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

<script> function loadXMLDoc(a) { var d= document.getElementById(hello).value; } </script>how can i get that id here
if you want to take value from current text then use onchange='loadXMLDoc(this.value) it will return value of changing input text
have look @ my edited answer...u will come to know how to get exact field value too..
1

Don't use foreach as bellow way.

foreach($sql1 as $value){

// don't generate html here

}

Because it may brake the html

Use foreach bellow way.

<?php

foreach($sql1 as $value):

?>

<tr>
 <td><input type=text id='hello' name='hello' data-id="<?php echo  $value['username']?>"    onchange='loadXMLDoc(this);' value=<?php echo $value['username']?>>
   <td><input type=text id='uid' name='uid' onchange='loadXMLDoc(this).' value=<?php echo  $value['id']?>>
</tr>

<?php endforeach() ?>

Comments

0

use the uniqid() function $str=uniqid("uid") it will make some thing like ti uid1hq7266
and print it in the input

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.