I am developing an laboratory management app which requires the user to add multiple test by click on add button before submitting. I clone the div containing the select test and the test price. My problem is how to attach unique value to the cloned test-price as the id
$(document).ready(function() { $("#addbtn").on("click", function(e) { e.preventDefault(); let uniqueid = Date.now(); $('#testdone') .clone().val('') // CLEAR VALUE. .appendTo("#appendcontainer"); }); $("#select-test").on("change", function() { console.log($(this).val()); }) });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="testdone"> <div class="row my-4"> <div class="col-md-6"> <select name="tests[]" class="form-control" id="select-test"> <option value="">Select Patient Test</option> @foreach ($tests as $item) <option value="{{$item->id}}">{{$item->name}}</option> @endforeach </select> @if ($errors->first("referred_by")) <span>{{$errors->first("referred_by")}}</span> @endif </div> <div class="col-md-6 test-price"> <input type="text" name="price" value="" id="price"> <div class="price-value"></div> </div> </div> </div>
2.1m questions
2.1m answers
60 comments
57.0k users