Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Enable edit mode in a Dynamic HTML Table

    Dear all Gurus,

    I'm stucked with below logic. Wanna get your advice to find out where I went wrong.Please help....

    Below is my Coding done.
    A dynamic HTML table is generated text boxes in table Rows(Dissable mode) with EDIT & DELETE buttons. When user clicks on Edit button, particular row(Text Box) should be enable to edit the values generated.

    But Unfortunately in my coding, always the fist row only gets enabled.

    <script type="text/javascript">
    function m(id){

    document.getElementById('Record_id').disabled=false;
    document.getElementById('file_number').disabled=false;
    return false;
    }
    </script>



    PHP Code:
    while ($rw mysql_fetch_array($query1)) {$k $rw['Record_id'];echo '<tr>';echo'<form name = "t_data">';echo '<td>'.'<input type="text" id="Record_id" name="Record_id"value="'.$rw['Record_id'].'" disabled="true" size ="5"/>'.'</td>';echo '<td>'.'<input type="text" id="file_number" name="file_number" value="'.$rw['file_number'].'" disabled="true" size = "9"/>'.'</td>';echo '</tr>'; echo '<tr>';echo' <td>';echo'<form action="dlt_grid.php" method = "GET">';echo'<input type="submit" value="Delete">';echo'<input type="hidden" name="hf" value="'.$k.'">';echo'</form> ';echo'</td>';                   echo' <td>';echo'<input type="submit" id="'.$k.'" value="Edit" onclick = "return m(this.id)">';echo'<input type="hidden" name="hf" value="'.$k.'">';echo'</td>';echo '</tr>';echo'</form>'

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    ids are supposed to be unique. If you look in the HTML generated by that PHP (which is all you should really post here), you will see a lot of duplicate ids.

    It looks like if you appended $k to the IDs you would be able to reference the elements unambigiously:

    PHP Code:
    while ($rw mysql_fetch_array($query1)) {
        
    $k $rw['Record_id'];
        echo 
    '<tr>';
        echo
    '<form name = "t_data">';
        echo 
    '<td>'.'<input type="text" id="Record_id_'.$k.'" name="Record_id"value="'.$rw['Record_id'].'" disabled="true" size ="5"/>'.'</td>';
        echo 
    '<td>'.'<input type="text" id="file_number_'.$k.'" name="file_number" value="'.$rw['file_number'].'" disabled="true" size = "9"/>'.'</td>';
        echo 
    '</tr>';
        echo 
    '<tr>';
        echo
    ' <td>';
        echo
    '<form action="dlt_grid.php" method = "GET">';
        echo
    '<input type="submit" value="Delete">';
        echo
    '<input type="hidden" name="hf" value="'.$k.'">';
        echo
    '</form> ';
        echo
    '</td>';
        echo
    ' <td>';
        echo
    '<input type="submit" id="'.$k.'" value="Edit" onclick = "return m(this.id)">';
        echo
    '<input type="hidden" name="hf" value="'.$k.'">';
        echo
    '</td>';
        echo 
    '</tr>';
        echo
    '</form>';

    Code:
    function m(id){
    	document.getElementById('Record_id_'+id).disabled=false;
    	document.getElementById('file_number_'+id).disabled=false;
    	return false;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •