admin管理员组

文章数量:1406177

This is a continuation from a previous question the I made. Basically I'm using AJAX to call a php insert statement.

This is te bit im stuck on:

HTML/PHP

    <select name="status" id='000042'>
      <option value=''>--Select--</option>
      <option value='Approve'>Approve</option>
      <option value='Reject'>Reject</option>
      <option value='Pending'>Pending</option>
    </select>

AJAX/JAVASCRIPT

$(document).ready(function(){
$('select').on('change',function () {
//$('select').change(function () {
        var statusVal = $(this).val();
        var job_id = $(this).id;
        alert(statusVal);
        $.ajax({
                 type: "POST",
                 url: "saveStatus.php",
                 data: { statusType : statusVal, jobID: job_id },
                 success: function(msg) {
                     $('#autosavenotify').text(msg);
                 }
      })
  });
});

The values for statusVal get stored just fine and when it calls thee insert statment it works great,
But the number i have used for id="" does not store into the ajax variable job_id, is there a way to do this?

Thanks

Ian

This is a continuation from a previous question the I made. Basically I'm using AJAX to call a php insert statement.

This is te bit im stuck on:

HTML/PHP

    <select name="status" id='000042'>
      <option value=''>--Select--</option>
      <option value='Approve'>Approve</option>
      <option value='Reject'>Reject</option>
      <option value='Pending'>Pending</option>
    </select>

AJAX/JAVASCRIPT

$(document).ready(function(){
$('select').on('change',function () {
//$('select').change(function () {
        var statusVal = $(this).val();
        var job_id = $(this).id;
        alert(statusVal);
        $.ajax({
                 type: "POST",
                 url: "saveStatus.php",
                 data: { statusType : statusVal, jobID: job_id },
                 success: function(msg) {
                     $('#autosavenotify').text(msg);
                 }
      })
  });
});

The values for statusVal get stored just fine and when it calls thee insert statment it works great,
But the number i have used for id="" does not store into the ajax variable job_id, is there a way to do this?

Thanks

Ian

Share Improve this question edited Jan 4, 2015 at 6:19 Harry 89.8k26 gold badges214 silver badges223 bronze badges asked Aug 22, 2013 at 13:28 snookiansnookian 8736 gold badges13 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Try var job_id = $(this).attr('id');

Try the below. Use the .prop method to access the id of the required field.

var job_id = $(this).prop('id');

Working Demo

本文标签: javascriptAJAX get id from select field as a variableStack Overflow