2016-12-05 10 views
1

検索入力と「追加」ボタンを備えたカスタム選択ボックスを使用しました。この入力フィールドは、検索のように動作し、ドロップダウンオプションの値を検索します。値が値と一致しない場合、この追加ボタンをクリックすると、このフィールドの値がオプションに追加され、ドロップダウンの選択値として機能する必要があります。 ...選択ボックスの入力テキストフィールドの値を取得する方法オプション値

ありがとう..

$(function() { 
 
     $(".standards").customselect(); 
 
     });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src='http://classvita.com/admin/res/javascripts/jquery-customselect.js'></script> 
 
<link href='http://classvita.com/admin/res/stylesheets/jquery-customselect.css' rel='stylesheet' /> 
 
<select name='standard' class='custom-select standards'> 
 
    <option value=''>Add Particular</option> 
 
    <option value='1'>abc</option> 
 
    <option value='2'>aabc</option> 
 
    <option value='3'>abbc</option> 
 
</select>

+0

今まであなたの完全なコードを追加します。私たちはあなたの追加ボタンと他の詳細が分かりません – ScanQR

+0

ちょうど追加をクリックすると、ドロップダウンがあり、最後に追加ボタンがあります..そのコードはリンクされたjsファイルにあります –

+0

新しいアイテムを追加しますか?それはプラグインによって生成されますか? – ScanQR

答えて

0

これは解決策ではありませんが、これはあなたのソリューションに到達するための方法です助けてください。ここ

<select name='standard' class='custom-select standards' id="SelectList"> //add id attribute 
<option value=''>Add Particular</option> 
<option value='1'>abc</option> 
<option value='2'>aabc</option> 
<option value='3'>abbc</option> 
</select> 

は、あなたが選択リスト項目を追加する方法です。

JS:

var html = "<option value=\""+ ListItemNumber +"\">"+ TheSearchTerm +"</option>"; 
$('#SelectList').append(html); //binding the html 
$('#SelectList').val(ListItemNumber); //Select the ListItem 

はこれがあなたのお役に立てば幸いです.....

0

あなたはclickを添付する必要がありますイベントのAdd New Itemボタンをクリックし、そのボタンをクリックすると、新しいオプションを作成し、customに次のように選択してください。

$(document).on('click', "#add_new_button_id", function(){ 
    //get the value from input text 
    var typedValue = $("#input_id").val(); 
    //create option on click and add to your custom select 
    $('.custom-select').append($("<option></option>").attr("value", typedValue).text(typedValue)); 
}); 
+0

sry man ...失敗しました... –

+0

@AnkitJainはあなたの変更をポストし、どこが失敗したのですか? – ScanQR

0
$('body').on('change','select[name="standard"]',function(){ 

var pid = $(this).val(); //grabbing the current value of the select. 
if(check here if pid lies in some sort of arrays ,values etc) 
{ 
$('select[name="standard"]').append('<option value="'+pid+'">'+pid+'</option>'); 

} 
}); 
0

$(function() { 
 
     $(".standards").customselect(); 
 
     });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src='http://classvita.com/admin/res/javascripts/jquery-customselect.js'></script> 
 
<link href='http://classvita.com/admin/res/stylesheets/jquery-customselect.css' rel='stylesheet' /> 
 
<select name='standard' class='custom-select standards'> 
 
    <option value=''>Add Particular</option> 
 
    <option value='1'>abc</option> 
 

 
    <option value='2'>aabc</option> 
 
    <option value='3'>abbc</option> 
 
</select>

関連する問題