Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

javascript - how do I attach a unique uniqe for cloned input?

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>
question from:https://stackoverflow.com/questions/65857350/how-do-i-attach-a-unique-uniqe-for-cloned-input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...