1

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.

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?

I would really appreciate some help with that.

Thanks.

1 Answer 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")
        })
    })
Sign up to request clarification or add additional context in comments.

2 Comments

I was on this track. Actually I tried the following as a way to debug $("#theSelect option:selected").click(function(){ alert($("#theSelect option:selected").text()); }); but the alert doesn't work when I click and select a value.
No problem, glad i could help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.