验证gridview中的选定下拉值并使用所选值填充标签

时间:2015-09-13 22:28:25

标签: javascript jquery asp.net

我正在努力避免重复选择同一房间号码的人,并在选定人员身上填写标签。请参阅jsfiddle以了解问题

http://jsfiddle.net/bharatgillala/9o1gxa1h/4/

html

<table id="gridviewInfo" runatr="server">


 <TBODY><TR>
<TH scope=col>Available Person</TH>
 <TH scope=col>RooNumber</TH>
<TH scope=col>SelectedPerson</TH>

</TR>

<TR>
 <TD style="WHITE-SPACE: nowrap" align=left><SELECT    onchange=checkforvalue(this) id=ddlAvailableJudges name=ctl00$contentBody$gvwRoomInformation$ctl02$ddlAvailableJudges>

<OPTION selected value=>
</OPTION>
<OPTION  value=maxico>maxico
   </OPTION> <OPTION value=chennai>chennai</OPTION> <OPTION value=newdelhi>newdelhi</OPTION> <OPTION value=hongkong>hongkong</OPTION>    </SELECT> </TD>
 <TD style="WIDTH: 100px">1</TD>
<td>
<label > populate  </label>
</td>    
</TR>

<TR>
  <TD style="WHITE-SPACE: nowrap" align=left>

   <SELECT onchange=checkforvalue(this) id=ddlAvailableJudges name=ctl00$contentBody$gvwRoomInformation$ctl03$ddlAvailableJudges> 

    <OPTION selected value=>
  </OPTION>
    <OPTION  value=maxico>maxico</OPTION> <OPTION value=chennai>chennai</OPTION> <OPTION value=newdelhi>newdelhi</OPTION> <OPTION value=hongkong>hongkong</OPTION></SELECT> </TD>
<TD style="WIDTH: 100px">2</TD>

  <td>
  <label > populate  </label>
   </td>
   </tr>

1 个答案:

答案 0 :(得分:1)

您不能为下拉列表指定相同的ID(ID应该是唯一的)。这是代码。我已经为下拉列表添加了类名,并为每个下拉列表提供了唯一的ID。

这是link to the updated fiddle

    $('.judges').change(function(){
    //on change get selected dropdown's value
    var curVal = $('option:selected',this).val();
    //get the id of the dropdown changed
    var curId = this.id;
    //set the label with selected value
    $(this).parents().eq(1).find('td:nth-child(3) > label').html(this.value);
    //loop through all the dropdowns
    $('.judges').each(function() {
        //for each dropdown get the selected value
        var innerVal = $('option:selected',this).val();
        if(innerVal !== ''){
            //if id of the dropdown is different to that of the original dropdown selected & the selected values are the same clear the selection of the old dropdown
            if(innerVal === curVal && curId != this.id){
                $(this).val(" ");
                $(this).parents().eq(1).find('td:nth-child(3) > label').html('populate from selected');
            }
        }
        else {
            $(this).parents().eq(1).find('td:nth-child(3) > label').html('populate from selected');
        }
    });
});