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 badges2 Answers
Reset to default 4Try 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
版权声明:本文标题:javascript - AJAX get id from select field as a variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744272078a2598230.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论