Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This block of code is inside a loop:

PHP
<label id=\"col_{$child_column_id}\">{$child_column_id}</label>

<input type=\"text\" id=\"{$child_column_id}\" onblur=\"cancelRename(this, this.id)\" style=\"display:none\">

<br>

<label id=\"{$child_column_id}\" onclick=\"renameColumn(this.id, this.id)\">Rename</label> /

<a href=\"".base_url()."index.php/table/deleteCol/{$child_column_id}\"> Delete</a> /

<a href=\"".base_url()."index.php/table/insertNewColumn/1/{$child_column_id}\">Split</a></td>";



When I click on Rename, it should change to 'Save' and the label holding the id/name of the column should change to a textbox. When I click on Save, it will commit the changes to the database; if the user clicks outside the textbox, it will cancel the changes and go back to being a label. 'Save' will become 'Rename' again.

What I have tried:

JavaScript
//on click: show textbox, hide label
      function renameColumn(label_id, inputText_id)
      {
        alert('Entered rename' label_id);
        //change 'Rename' to 'Save'
        document.getElementById(label_id).innerHTML = 'Save';
        $(label_id).css('display', 'none');
        $(inputText_id)
        .val($(label_id).text())
        .css('display','')
        .focus();
      }

      //on blur
      function cancelRename(editText, label)
      {
        document.getElementById(label).innerHTML = 'Rename';
        $(editText).css('display', 'none');
        //$(column_id)
        .css('display', '');
      }

      //on save
      function saveColumnName(editText_value, column_id)
      {

        document.getElementById(label).innerHTML = 'Rename';
      }
Posted
Comments
Ayodeji Oluwatomiwo 9-Jan-17 5:21am    
can't you just try and hide the label and reveal the textbox??
ZurdoDev 9-Jan-17 7:31am    
You just need to debug it to find what is wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900