Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new text field when button is clicked [closed]

I want to create a form for my client. My client require to create a dynamic for him. Suppose, I want to insert 1 record in main table of mysql, and record multiple records in secondary table which has reference key of main table. I don't know how many records against the main table, it maybe one at time or multiple records at time. I want to do it with single form. If client click add more button it show another text field to insert more data. how I can do it ?????

like image 605
Aneeq Tariq Avatar asked Nov 17 '12 10:11

Aneeq Tariq


People also ask

How do you reset a text box in HTML?

The <input type="reset"> defines a reset button which resets all form values to its initial values.


2 Answers

It would be possible using pure javascript

like this

<input type="button" onclick="addInput()"/>

<span id="responce"></span>
<script>
var countBox =1;
var boxName = 0;
function addInput()
{
     var boxName="textBox"+countBox; 
document.getElementById('responce').innerHTML+='<br/><input type="text" id="'+boxName+'" value="'+boxName+'" "  /><br/>';
     countBox += 1;
}
</script>
like image 122
vivek salve Avatar answered Sep 18 '22 06:09

vivek salve


This is possible through the jquery/javascript.

So you can use this reference :http://www.mkyong.com/jquery/how-to-add-remove-textbox-dynamically-with-jquery/

Just try it!!

like image 28
Daxen Avatar answered Sep 22 '22 06:09

Daxen