Home > Mobile >  How to fetch the dropdown value in edit form using jquery?
How to fetch the dropdown value in edit form using jquery?

Time:05-10

I have a form with dropdown in it and when I am adding the data it is going to database. When I click on edit I can fetch the values of all other fields but the drop down is not showing the value which was added previously in the dropdown can some one please help ??

I am trying to do this with jquery ,

I am using semantic for frontend with jsp and servlet for the backend and database in postgres

this is what i have tried found this on semantic behavior but its only setting the value as default

$("#iddropdown").dropdown('set selected', ['fruits']);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js" integrity="sha512-dqw6X88iGgZlTsONxZK9ePmJEFrmHwpuMrsUChjAw1mRUhUITE5QU9pkcSox ynfLhL15Sv2al5A0LVyDCmtUw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" integrity="sha512-8bHTC73gkZ7rZ7vpqUQThUDhqcNFyYi2xgDgPDHc GXVGHXq xPjynxIopALmOPqzo9JZj0k6OqqewdGO3EsrQ==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div >
  <label> Product Category </label>
  <select id="iddropdown"  name="category">
    <option value="category"> Category </option>
    <option value="fruits"> Fruits </option>
    <option value="vegetables"> Vegetables </option>
    <option value="rice"> Rice </option>
    <option value="flour"> Flour </option>
    <option value="snacks"> Snacks </option>
    <option value="beverages"> Beverages </option>
    <option value="sauces"> Sauces </option>
    <option value="cereal"> Cereal </option>
    <option value="spices"> Spices </option>
    <option value="pulses"> Pulses </option>
    <option value="cheese"> Cheese </option>
  </select>
</div>

CodePudding user response:

$("#iddropdown").dropdown('set selected', ['${product.category}'] );

Finally this worked for me !!

  • Related