Hi here i have one button , when I click that add element
button two input field will come like one by one for this i have used clone()
function .here my problem is after given some values for each input files and click the submit
button i got only one field value .
here is my code
<html>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script>
$(document).ready(function(){
$('#btn1').click(function(){
var $div = $('div[id^="trace-div"]:last');
var num = parseInt( $div.prop("id").match(/\d+/g), 10 ) +1;
var $klon = $div.clone().prop('id', 'trace-div'+num );
$klon.find("input[name='t1_x_axis']").attr("id", "x_axis_t"+num).val("");
$klon.find("input[name='t1_y_axis']").attr("id", "y_axis_t"+num).val("");
$div.after( $klon);
});
});
function chartsubmitbtn(){
var clones = $("input:text").clone();
//var str = JSON.stringify(clones);
console.log(clones.val());
return true;
}
</script>
<body>
<button type = "button" id = "btn1" > Add element</button>
<div id = "trace-div1">
<h4><b>Trace 1 </b></h4>
<form>
<table>
<tbody>
<tr>
<td><label>X Axis: </label></td>
<td><input type="text" name="t1_x_axis" id="x_axis_t1" size="50"></td>
</tr>
<tr>
<td><label>Y Axis: </label></td>
<td><input type="text" name="t1_y_axis" id="y_axis_t1" size="50"></td>
</tr>
</tbody>
</table>
</form>
</div>
<button type="button" id="chart-report-submit" onclick="chartsubmitbtn();">Submit</button>
</body>
</html>
Note:if i don't use val()
in console.log() it is giving json
data.from that how can i get my values .
Thanks