0

Here is my code

javascript:

<script type="text/javascript">
$(function() {
    var scntDiv = $('.create');
    var i = $('.create table').size() + 1;
    $('.add').live('click', function() {
            $('<table><tr><td><input type="text" name="item' + i +'" id="textbox_input" placeholder="Item" /></td><td> <input type="number" name="qtty'+ i + '" id="textbox_number" placeholder="Qtty'+i+'"/></td><td><button type="button" class="remove" id="button">Remove</button></td></tr></table>').appendTo(scntDiv);
            i++;
var number = i;
            return false;
    });
    $('.remove').live('click', function() { 
            if( i > 1 ) {
                    $(this).parents('table').remove();
                    i--;
            }
            return false;
    });
}
});
 </script>

.html:

<div class="create" style=" padding:10px; width:450px; -moz-border-radius:10px;-webkit-    border-radius:10px; top:10px; left:10px; height:540px; background-color:#FFF; position:absolute; overflow:scroll;">

<form method="POST" action="create.php">
<table>
<tr>
<td><input type="text" name="title" id="textbox_input" placeholder="Title"/></td>
<td></td>
<td><input type="submit" value="Save" class="save" id="button" /></td>
</tr>
<tr>
<td><input type="text" name="item1" id="textbox_input" placeholder="Item"/></td>
<td><input type="number" name="qtty1" id="textbox_number" placeholder="Qtty"/></td>
<td><button type="button" class="add" id="button">Add</button></td>
</tr>
</table>
</form>
</div>

i need to transfer the var number to create.php. The form is to create a checklist for users. as they click the add button, the item and quantity field will add. And as the add button is clicked, the var i will increase by 1 and the var number will save the last var i. The question is how to transfer var number to create.php?

serenna
  • 1
  • 4
  • In what way do you need to "transfer it to PHP"? As part of the form post with the rest of the inputs? – David Oct 23 '12 at 13:52
  • Please check this http://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php – Vishwesh Shetty Oct 23 '12 at 13:56
  • @David: In my create.php there will be the var number's value, and the item and quantity according to its number. for example, $_POST['item1']; $_POST['item2']; $_POST['item3']; . . . . until the end of the number's value – serenna Oct 23 '12 at 14:01

0 Answers0