Here is the script:
- Code: Select all
// JavaScript Document to add dynamic text boxes onto the registration form
$(document).ready(function(){
$counter = 0; // initialize 0 for limitting textboxes
$('#buttonadd').click(function(){
if ($counter < 10)
{
$counter++;
$('#buttondiv').append('<div><label>'+$counter+' Roommate Name:</label><input type="text" name="textbox[]" class="textbox" value="" /></div>');
}else{
alert('You cannot add more than 10 textboxes');
}
});
$('#buttonremove').click(function(){
if ($counter){
$counter--;
$('#buttondiv .textbox:last').parent().remove(); // get the last textbox and parent for deleting the whole div
}else{
alert('No More textbox to remove');
}
});
$('#buttonget').click(function(){
alert($('.textbox').serialize()); // use serialize to get the value of textbox
});
$('#dropdownadd').change(function(){
$('#dropdowndiv').html(""); // when the dropdown change set the div to empty
$loopcount = $(this).val(); // get the selected value
for (var i = 1; i <= $loopcount; i++)
{
$('#dropdowndiv').append('<div><label>'+i+' Roommate Name:</label><input type="text" name="textbox[]" class="textbox2" value="" /></div>');
}
});
});
Here i am calling this into my form:
- Code: Select all
...............................................
<td><div id="dropdowndiv" class="input-container"><script type="text/javascript" src="js/dynamic_add_users.js"></script>
<!-- this is where textbox will appear --></div></td>
</tr>
<tr> <td><label for="no_of_roomates" id="label">how many roomates:</label></td><td>
<div class="choices">
<select id="dropdownadd">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
</td></tr>
.....................................
i want to insert text boxes values into my database, can anyone tell me how can i do this??

