0

I'm making a wordpress theme options page, and one of the options I want to make is how to add/removes dynamic rows by that the user can make it when he want to add a block. something like this

<table id="block" width="350px" border="0">
    <tr>        
        <td> 1 </td><!--Nomber of the row-->
        <td><input type="text" /><br /><label>Title</label></td><!--Title of the row-->

        <td><input type="text" /><br /><label>IMG Link</label></td><!--Image of the row-->

        <td><textarea  type="textarea" cols="40" rows="2"></textarea><br /><label>Description</label></td>
    </tr>
</table>


Beside I want to make it saved to wordpress when updating are saved .

1
  • R.Karar, while this is a very old question, you're still active. So I wanted to inform you that as @manetsus realized (in a suggested edit), your imageshack link is broken. If possible, you might consider restoring the image in a sustainable way (i.e. through SO's imgur account) in order to preserve your post for eternity;) Commented Oct 12, 2015 at 18:16

1 Answer 1

1

I'm not sure if this is what you wanted, but I posted a demo here.

HTML/CSS

<input id="addRow" type="button" value="Add Row">
<table id="block" width="350px" border="0">
 <tr>
  <td> 1 </td><!--Nomber of the row-->
  <td><input type="text" /><br /><label>Title</label></td><!--Title of the row-->
  <td><input type="text" /><br /><label>IMG Link</label></td><!--Image of the row-->
  <td><textarea  type="textarea" cols="40" rows="2"></textarea><br /><label>Description</label></td>
 </tr>
</table>

<style type="text/css"> 
#block { width: 50%; padding: 5px; }
#block td { vertical-align: top; }
</style>

Script

$(document).ready(function(){
 var newRow = '\
  <tr>\
   <td>\
    <span class="index"></span> \
    <input id="removeRow" type="button" value="X" title="remove this row">\
   </td>\
   <td><input type="text" /><br /><label>Title</label></td><!--Title of the row-->\
   <td><input type="text" /><br /><label>IMG Link</label></td><!--Image of the row-->\
   <td><textarea  type="textarea" cols="40" rows="2"></textarea><br /><label>Description</label></td>\
  </tr>';

 $('#addRow').click(function(){
  $('#block').append(newRow);
  reIndex();
 })

 $('#removeRow').live('click', function(){
  $(this).closest('tr').remove();
  reIndex();
 })

 function reIndex(){
  $('#block').find('.index').each(function(i){
   $(this).html(i+2);
  })
 }

})
Sign up to request clarification or add additional context in comments.

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.