1

i have a form that has select boxes. this form has a table and each row has been created by php while loop from database. for example

<select name="1265483" id="1265483" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>


<select name="5894253" id="5894253" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>

the id of each select is that entry's id in database. i want to get those ids to make an onchange function then send that id to ajax.

2
  • Is it necessary for you to select your select elements via their ids, or would it also be possible to select them via a more general selector? Commented Jul 8, 2015 at 11:16
  • no necessity to select via their ids. i just want to send the id to ajax process. Commented Jul 8, 2015 at 11:27

3 Answers 3

2

You can use something like:

$("select").change(function () {
    $this = $(this);
    $.post("some/url/dot.php", {data: $this.attr("id")}, function () {
        // code...
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

you can do by below code

      var your_selected_value = $('#5894253 option:selected').val();

            $.ajax({
              type: "POST",
              url: "your_url",
              data: {selected: your_selected_value},
              success: function(data) {
                // Stuff
              },
              error: function(data) {
                // Stuff
              }
            });

put this code in onchange function

2 Comments

thanks for your answer. but that id has been randomly generated via php. i cannot write this code with specific id.
than you can use $('.form-control option:selected').val();
0

Try using the select class name:

$("select.form-control").change(function (e) {
    var selectId = $(this).attr('id'),
    ajaxUrl = "demo_test.php?id=" + selectId;
    $.ajax({
        url: ajaxUrl,
        success: function (result) {
            if (result) {
                //success code 
            }
        }
    });
});

Comments

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.