2016-06-17 6 views
0

現在、フォーム上で作業しています。セグメントの1つに2つの要素のドロップダウン選択があり、その隣に2つのラジオボタンが関連付けられています。 ラジオボタンのうちの1つは通常(非入力テキストボックス)であり、他のラジオボタンはカスタム入力入力テキストボックス用です。 ユーザーが最初にドロップダウンで要素を選択し、選択に基づいて、ユーザーが入力テキストボックスのない最初のラジオボタンをクリックした場合、このラジオボタンの値はドロップダウンの選択に基づいて割り当てられます..ラジオボタンベースのドロップダウン選択に値を割り当てます。

以下

は私のhtmlコードです:ユーザーはから「DBUSER」を選択した場合

<div class="uriDiv input-group"> 
    <select class="common authSelect form-control" name="authType" id="authType"> 
    <option value=""> 
     <spring:message code="newPolicy.selectAuthType"></spring:message> 
    </option> 
    <option value="DBUser">DBUser</option> 
    <option value="LDAPUser">LDAPUser</option> 
    </select> 
</div> 

<div class="auth-permission-rd"> 
    <div class="uriDiv radio radio-left"> 
    <label> 
     <input type="radio" class="common anyuser" value="anyUser" name="authPermission" id="authPermission">Any User 
    </label> 
    </div> 
    <div class="uriDiv radio radio-input"> 
    <label> 
     <input type="radio" class="common groupuser" value="groupUser" name="authPermission" id="authPermission"> 
     <input type="text" name="authPermissionValue" disabled="disabled" class="common form-control-placeHolder" id="authPermissionValue" placeholder="Enter custom Permissions - Comma separated" /> 
    </label> 
    </div> 
</div> 

私はそう...ラジオボタンに値を割り当てるために、

をjqueryのコードを持っている必要がありますドロップダウンし、「AnyUser」ラジオボタンを選択した場合、jquery機能は「AnyDBUserValu

ユーザがドロップダウンリストからLDAPUserを選択し、「AnyUser」ラジオボタンを選択した場合、jquery機能はこの値をラジオボタンの「AnyLDAPUserValue」に割り当てる必要があります。 。

、ユーザが入力したテキストボックスを持っている他のラジオボタンを選択することによって、カスタム値を入力したい場合は、その後、我々はそれらの以前の値を破棄する必要があり、ユーザーが入力したカスタム値をとる。..

私はJqueryの初心者で、この機能のjqueryコードを書く際に助けが必要です。

ヘルプをよろしくお願いします。ありがとうございます。コードの下

+1

は、単一の質問に多くの質問を開始する方法をあなたのアイデアを与えることができます – Sami

答えて

0

はそれを正確にしてください...

$("#authType").change(function(){ 


}) 

$('input[name="authPermission"]').click(function(){ 
    if ($("#authType").val()=='DBUser' && $(this).val() =='anyUser'){ 
     $(this).val('AnyDBUser'); 
    } 
    if ($("#authType").val()=='LDAPUser' && $(this).val() =='anyUser'){ 
     $(this).val('AnyLDAPUser'); 
    } 
}) 
1
First you will perform drop down event like this... 

$("#authType").change(function(){  
     $("#authPermissionValue").val($("[type = radio]").val().split("U")[0].toUpperCase() + $("#authType").val()) 
    }) 

or also like this.. 

$("#authType").change(function(){  
     $("#authPermissionValue").val("ANY" + $("#authType").val()) 
    }) 

and after this you can perform radio button even like this... 

$(".groupuser").on("click", function(){   
     $("#authPermissionValue").removeAttr("disabled"); 
     $("#authPermissionValue").val(""); 
    }); 

That solution is totally dynamic of your requirements. 
no need to add extra hard code for conditions 
関連する問題