如果选择已在警报中获取空值,则禁用所选选项

时间:2016-04-04 08:22:55

标签: javascript jquery

大家好我正在使用此脚本来检查是否已选择某个选项然后禁用该选项,现在我正在尝试获取所选值但我没有收到任何警报。

HTML

<h4 class="info-text">Select 1st Employee<br>
   <select name="wcl-employees1" id="wcl-employees1">
    <option value="" disabled="" selected="" style="display:none;">Select One...</option>
    <option value="ALCANTARA, ERIC">ALCANTARA, ERIC</option>
    <option value="ALDRIGE, ,MERANDA">ALDRIGE, ,MERANDA</option>
    <option value="ALTOBELLI, JAMES">ALTOBELLI, JAMES</option>
</select>

<h4 class="info-text">Select 2nd Employee<br>
         <select name="wcl-employees2" id="wcl-employees2">
        <option value="" disabled="" selected="" style="display:none;">Select One...</option>
    <option value="ALCANTARA, ERIC">ALCANTARA, ERIC</option>
    <option value="ALDRIGE, ,MERANDA">ALDRIGE, ,MERANDA</option>
    <option value="ALTOBELLI, JAMES">ALTOBELLI, JAMES</option>
</select>

<h4 class="info-text">Select 3rd Employee<br>
   <select name="wcl-employees3" id="wcl-employees3">
    <option value="" disabled="" selected="" style="display:none;">Select One...</option>
    <option value="ALCANTARA, ERIC">ALCANTARA, ERIC</option>
    <option value="ALDRIGE, ,MERANDA">ALDRIGE, ,MERANDA</option>
    <option value="ALTOBELLI, JAMES">ALTOBELLI, JAMES</option>
</select>

<Script>
var $select = $("select");
$select.on("change", function() {
    var selected = [];  
    alert(selected);
    $.each($select, function(index, select) {           
        if (select.value !== "") { selected.push(select.value); }
    });         
   $("option").prop("disabled", false);         
   for (var index in selected) { $('option[value="'+selected[index]+'"]').prop("disabled", true); }
});

数据库插入代码:

public function insertTeam()
{
    $team_code=$_POST['fav1'].','.$_POST['fav2'].','.$_POST['fav3'].','.$_POST['fav4'].','.$_POST['fav5'];
    $user_id  =$_POST['fav6'];
    $verified = self :: checkFavTeams( $_POST['fav6'] );

    if($verified['totalrow']>0)
    {
        $sql=$this->db->prepare("update favteam set team_code='$team_code' where user_id='$user_id'");
        $sql->execute();
        if ( $sql->rowCount() != 0 ) {
                return( 1 );
            }  else {
                  return ( 3 );
             }
    }
    else
    {
        $sql = $this->db->prepare("insert into favteam (team_code,user_id) values ('$team_code','$user_id')");
        $sql->execute();
        if ( $sql->rowCount() != 0 ) {
                    return( 1 );
                }  else {
                      return ( 3 );
                 }
    }
}

0 个答案:

没有答案