2016-10-06 8 views
0

現在、ラジオボタンからの優先通信方法をユーザーが選択したことに基づいて、赤い星印が表示されます。たとえば、優先通信方法を選択すると値が表示されます。電話番号「赤色の星印」は、他のラジオボタンを選択すると非表示になります。つまり、優先通信方法は電子メールです。しかし、どうすれば問題なのですか?電話番号を選択すると赤い星印が「電話番号を入力してください」と「電話番号を確認」の近くに表示され、「電話番号を入力してください」にテキストを入力し、赤い星が消える形でsubmitを押してください。私はこれらの赤い開始を表示したままにしたい、私はこの機能を再度呼び出さなければならないと思います、助言してください?赤い星が表示されたままにしておきますか?

$('.communicationCB input[name=CCommmunication]').click(function() { //.communication class passed input name == model public communication 
     if ($(this).val() == "TelephoneNo") { //if value TelephoneNo selected in model 
      $('.confirmmobtelno').show(); //show this text box 
      $('.redstar').show(); //shows red star when Mobile option is selected 
     } else { 
      $('.confirmmobtelno').hide(); //hide textbox 
      $('.redstar').hide(); //Hides red star 
     } 

     if ($(this).val() == "TelephoneNoAlternative") { //if value == to TelephoneNoalternative 
      $('.confirmalttelno').show(); //show confirm alt tel no text box 
      $('.redstaralttel').show(); //shows red star when Alt telephone option is selected 
     } else { 
      $('.confirmalttelno').hide(); //else hide it 
      $('.redstaralttel').hide(); //Hides red star 

     } 

    }); 
+1

あなたはページのリロードでこれを維持したいですか?はいの場合は 'localStorage'にデータを格納する必要があります –

+0

あなたの" submit "機能を表示することもできますか?また、重要なのは、ユーザーが空の「確認ボックス」でフォームを送信することを許可しているか、フィールドが有効でない場合に送信を停止したいのですか? –

答えて

0

これは推測です。とにかく試してみる。

この機能は、クリック機能にバインドされています。だからあなたはそのアイテムをクリックするだけで起動します。フォームが送信された後、星を表示するかどうかを(ページの読み込み時に)見たいと思う。 、

$(function() { 
    if ($('.communicationCB input[name=CCommmunication]').val() == "TelephoneNo") { //if value TelephoneNo selected in model 
     $('.confirmmobtelno').show(); //show this text box 
     $('.redstar').show(); //shows red star when Mobile option is selected 
    } else { 
     $('.confirmmobtelno').hide(); //hide textbox 
     $('.redstar').hide(); //Hides red star 
    } 

    if ($('.communicationCB input[name=CCommmunication]').val() == "TelephoneNoAlternative") { //if value == to TelephoneNoalternative 
     $('.confirmalttelno').show(); //show confirm alt tel no text box 
     $('.redstaralttel').show(); //shows red star when Alt telephone option is selected 
    } else { 
     $('.confirmalttelno').hide(); //else hide it 
     $('.redstaralttel').hide(); //Hides red star 

    } 

}); 

あるいはさらに良いの両方を兼ね備え:

だからこれのonload関数を追加

function checkComm() { 
    if ($('.communicationCB input[name=CCommmunication]').val() == "TelephoneNo") { //if value TelephoneNo selected in model 
     $('.confirmmobtelno').show(); //show this text box 
     $('.redstar').show(); //shows red star when Mobile option is selected 
    } else { 
     $('.confirmmobtelno').hide(); //hide textbox 
     $('.redstar').hide(); //Hides red star 
    } 

    if ($('.communicationCB input[name=CCommmunication]').val() == "TelephoneNoAlternative") { //if value == to TelephoneNoalternative 
     $('.confirmalttelno').show(); //show confirm alt tel no text box 
     $('.redstaralttel').show(); //shows red star when Alt telephone option is selected 
    } else { 
     $('.confirmalttelno').hide(); //else hide it 
     $('.redstaralttel').hide(); //Hides red star 

    } 
}; 
$(function() { checkComm(); }); 
$('.communicationCB input[name=CCommmunication]').click(function() { checkComm(); }); 
関連する問題