<div class="row">
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Act</label>
<input type="text" class="form-control" v-model="act" >
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Section </label>
<input type="text" class="form-control" v-model="section">
</div>
</div>
<button>Add row</button>
</div>
So, when I click on add button, i need to keep on adding the above row. How can I able to add this row when I click on add row button.
I need to pass values as BOOKED UNDER :
[{
act :,
section:,
}]
If I have more rows i need to pass values as comma seperated. I am weak in js and this is my first project having this kind of problem. How can I able to add values in this way.
My vue js code is
addForm = new Vue({
el: "#addForm",
data: {
bookedUnder:[],
act: '',
section:'',
},
methods: {
handleSubmit: function(e) {
var vm = this;
data['otherNatureofOffense'] = //in the abve way
$.ajax({
url: 'http://localhost:3000/record/add/f/',
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if (e.status) {
vm.response = e;
alert("success")
} else {
vm.response = e;
console.log(vm.response);
alert(" Failed")
}
}
});
return false;
},
},
});
Please help me to have a solution
If you use pure javascript this may helpful
var count=1;
$("#btn").click(function(){
$("#container").append(addNewRow(count));
count++;
});
function addNewRow(count){
var newrow='<div class="row">'+
'<div class="col-md-4">'+
'<div class="form-group label-floating">'+
'<label class="control-label">Act '+count+'</label>'+
'<input type="text" class="form-control" v-model="act" >'+
'</div>'+
'</div>'+
'<div class="col-md-4">'+
'<div class="form-group label-floating">'+
'<label class="control-label">Section '+count+'</label>'+
'<input type="text" class="form-control" v-model="section">'+
'</div>'+
'</div>'+
'</div>';
return newrow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div id="container">
<div class="row">
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Act</label>
<input type="text" class="form-control" v-model="act" >
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Section </label>
<input type="text" class="form-control" v-model="section">
</div>
</div>
</div>
</div>
<button id="btn">Add row</button>
Try please,
document.getElementById("clickMe").onclick = function () {
//first div
var newDivCol = document.createElement("div");
newDivCol.setAttribute("class","col-md-4");
//second div
var newDivForm = document.createElement("div");
newDivForm.setAttribute("class","form-group label-floating");
newDivCol.appendChild(newDivForm);
//label
var newlabel = document.createElement("label");
newlabel.setAttribute("class","control-label");
newlabel.innerHTML = "Here goes the text";
newDivForm.appendChild(newlabel);
//input
var newInput = document.createElement("input");
newInput.setAttribute("type","text");
newInput.setAttribute("class","form-control");
newInput.setAttribute("v-model","act");
newDivForm.appendChild(newInput);
var element = document.getElementById("addRowsHere");
element.appendChild(newDivCol);
};
<div class="row" id="addRowsHere">
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Act</label>
<input type="text" class="form-control" v-model="act" >
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Section </label>
<input type="text" class="form-control" v-model="section">
</div>
</div>
</div>
<button id="clickMe">Add row</button>
I've 1000's of users and user data looks like the below. Some users have the devices as [{some data}] (array), some users have devices as {some data}, and some users have devices as empty []. I ...
I've 1000's of users and user data looks like the below. Some users have the devices as [{some data}] (array), some users have devices as {some data}, and some users have devices as empty []. I ...
I want to make a function that takes an array as an argument, creates a random number from 1 - 10, and runs until it creates a number that is not in the array, and returns it. Here is jsfiddle ...
I want to make a function that takes an array as an argument, creates a random number from 1 - 10, and runs until it creates a number that is not in the array, and returns it. Here is jsfiddle ...
i am trying to submit a form via Jquery when change event occurs in select field like this: $('select#slc_level').change(function(event){ event.preventDefault(); console.log('changed') $('form#...
i am trying to submit a form via Jquery when change event occurs in select field like this: $('select#slc_level').change(function(event){ event.preventDefault(); console.log('changed') $('form#...
I would like to repeat a text for 2 seconds in a while loop. How do I break the loop after 2 seconds? This is what I have tried so far but it doesn't work: var repeat = true; setTimeout(function() {...
I would like to repeat a text for 2 seconds in a while loop. How do I break the loop after 2 seconds? This is what I have tried so far but it doesn't work: var repeat = true; setTimeout(function() {...