0

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 class="eight wide field">
  <label> Product Category </label>
  <select id="iddropdown" class="ui dropdown" 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>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
SnIpEr ReLoAdEd
  • 72
  • 1
  • 10
  • 2
    I made you a snippet. What is the expected behaviour here? It seems to do what you set out to do – mplungjan Apr 20 '22 at 06:39
  • 1
    @mplungjan thanks for answering you are right but i am trying to fetch value other than fruits its fetching fruits it even though the value was somenthing else say if its snacks. i tried using set value(value) from semantic behavior which is most suitable for my case but its not working – SnIpEr ReLoAdEd Apr 20 '22 at 06:52
  • 2
    It is not clear what you are trying to do. According to the [manual](https://semantic-ui.com/modules/dropdown.html#/usage), you can get the text using `get text` and get the value using `get value` – mplungjan Apr 20 '22 at 06:57
  • 2
    More here: https://stackoverflow.com/questions/37550710/how-to-get-value-of-dropdown-menu-in-semantic-ui – mplungjan Apr 20 '22 at 06:59
  • 1
    i am trying to get the value which i selected earlier while adding the product say lf i selected vegetables earlier then while editing the form vegetables should be fetched in dropdown any guidance where i am going wrong ?? – SnIpEr ReLoAdEd Apr 20 '22 at 07:03
  • 2
    I am sorry, You repeat what you want a few times, but the usecase is unclear. You can cache all in an object and create the dropdown from that – mplungjan Apr 20 '22 at 07:05
  • 1
    ok will will try what you said and i will refer the link also will let you know – SnIpEr ReLoAdEd Apr 20 '22 at 07:10

1 Answers1

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

Finally this worked for me !!

SnIpEr ReLoAdEd
  • 72
  • 1
  • 10