开发者

get drop down box attributes

In the below i have a a div with employee names and ahave to assign a grade for them,my question is that i have get the empid for all the selected values in getgrade_values function.Using jquery how to get the ids of the drop down box with its value where the values are selected when on c开发者_JAVA技巧lick of evaluate function

  function getgrade_values(empid)
  {
           var ele='<select id="'+ empid +'" name="emp" style="width:40px;margin:0px 0pt;" >';
           ele +=  '<option value=""></option>';
           ele +=  '<option value="A">A</option>';
           ele +=  '<option value="B">B</option>';
           ele +=  '<option value="C">C</option>';
           ele +=  '<option value="D">D</option>';
           ele +=  '<option value="E">E</option>';
           ele +=  '<option value="F">F</option>';
           ele += '</select>';
        return ele;
  }


  function sendparams(data)
  {
        if(data.status == 1)
        {

           var ele='<tr id="std"><td><b>Evaluate:</b></label>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>';
           for(var l=0;l<data.emparr.length;l++)
           {
              ele +=  '<tr><td><div id="'+ data.emparr[l].id +'">' + data.emparr[l].name + "</td><td>" + getgrade_values(data.emparr[l].id) + '</div></td></tr>';
           ele+= '<input type="button" value="Evaluate" onclick="evaluate();"';
           }

   }


var select = $('select[name="emp"]')
var empId = select.attr('id')
alert('empId = '+empId)
select.children('option:selected').each(function() {
    alert('grade selected = ' + $(this).val())
})

DEMO : http://jsfiddle.net/hdTEP/


Currently, you will have 2 elements with id="<employeeId>". As ids should be unique across an entire page, you should consider appending the type of element you are representing, for example id="<employeeId>_gradeInput" for your grade dropdown. Next, for each user it seems like you have a button to submit a grade. I would call evaluate with the employee id associated with that button.

function getgrade_values(empid){
    var ele='<select id="'+ empid +'_gradeInput" name="emp" style="width:40px;margin:0px 0pt;" >';
    ..//Remaining code
}

function sendparams(data) {
if (data.status == 1) {
    var ele = 
        '<tr id="std">' + 
            '<td>' + 
                '<b>Evaluate:</b>' + 
            '</td>' + 
        '</tr>';
    for (var l = 0; l < data.emparr.length; l++) {
        var employeeId = data.emparr[l].id;
        ele += 
            '<tr>' +
                '<td>' +
                    '<div id="' + employeeId  + '_divContainer">' +
                        data.emparr[l].name +
                    '</div>' 
                '</td>' +
                '<td>' + 
                    getgrade_values(employeeId)
                '</td>' +
            '</tr>';
        ele += '<input type="button" value="Evaluate" 
                    onclick="evaluate(' + employeeId + ');"';
    }
}

function evaluate(employeeId){
    var gradeValue = $('#' + employeeId + '_gradeInput').val();
    ..//Your other evaluate code here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜