I have a dropdown menu (Select) that loads a bunch of data form my table. I'm trying to insert each value into another table on clicking each selection but I have no clue on how to go about this. I've been looking around and there is nothing much I can find.
我有一个下拉菜单(Select),它从我的表中加载一堆数据。我试图在单击每个选项时将每个值插入到另一个表中,但我不知道如何进行此操作。我一直在四处寻找,但我什么也找不到。
Here's my dropdown code:
这是我的下拉代码:
<select id="theSelect">
<option value="select">Select all that apply.</option>
<?php
for($i=0; $i<count($preferences); $i++){
?>
<option value="<?php echo $preferences[$i]['pname'];?>"><?php echo $preferences[$i]['pdesc'];?></option>
<?php
}
?>
</select>
What I want to do is each time I select a value from the dropdown, it makes an ajax request that inserts that value into another table. Is that possible?
我要做的是每次从下拉菜单中选择一个值时,它都会发出一个ajax请求,将该值插入到另一个表中。这有可能吗?
I would really appreciate some help with that.
我会非常感谢你的帮助。
Thanks.
谢谢。
1 个解决方案
#1
2
Are you looking for something like this?
你在找这样的东西吗?
$("#theSelect").on('change', function () {
var value = $('#theSelect option:selected').text();
$.post("urlToActionDbSave", { valueToInsert: value }, function () {
alert("your value have been saved to another table")
})
})
#1
2
Are you looking for something like this?
你在找这样的东西吗?
$("#theSelect").on('change', function () {
var value = $('#theSelect option:selected').text();
$.post("urlToActionDbSave", { valueToInsert: value }, function () {
alert("your value have been saved to another table")
})
})