如何使用jQuery以编辑表单以编辑形式获取下拉值?
我有一个列表的表格,当我将数据添加到数据库时。当我单击“编辑”时,我可以获取所有其他字段的值,但是下拉列表并未显示以前在下拉列表中添加的值,请有帮助吗?
我正在尝试使用jQuery来做到这一点,
我正在使用Smantic进行jsp和Servlet作为后端和Postgres中的数据库的frontent,
这是我尝试的,但它只是在语义行为上找到了这一点,但它仅将值设置为默认值
$("#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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,这对我有用!
Finally this worked for me !!