Home > Software design >  how to get html get id value in input
how to get html get id value in input

Time:03-01

hello I'm new in html I'm trying to get id value in input field. now I'm abele to get id value in dropdown input , now I'm trying to get in normal input.

I need get ID value in this input

 <div >
 <div >
     <label  > PRICE:<span style="color:red;">*</span> </label>
     <input    name="course_Price" id="course_Price" required> </div>
  </div>
  </div>

my script for get value in dropdown field

<script type="text/javascript">
    $(document).ready(function() {
        $('#student_courses').on('change', function() {
            var stateID = $(this).val();
            if(stateID) {
                $.ajax({
                    url: '/Student_Course_get_price/' stateID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {                      
                        $('#course_Price').empty();
                        $.each(data, function(key, value) {
                        $('#course_Price').append('<option value="'  value  '">''</option>');
                        });
                    } 
                });
            }else{
                $('#course_Price').empty();
            }
        });
    });
</script>

My dropdown input

  <div >
     <div >
         <label for="videoUrl1">Course Fees :<span style="color:red;">*</span></label>
          <select name="course_Price" id="course_Price"  data-dependent="course_Price">
       <option value=""></option>
          </select>
      </div>
   </div>

CodePudding user response:

In the success function of your ajax call, use $('#course_Price').val(value);

$.each(data, function(key, value) {
  $('#course_Price').append('<option value="'  value  '">''</option>');
  $(‘#course_Price’).val(value);
});
  • Related