LoginSignup
0
0

More than 5 years have passed since last update.

ラジオボタンと不活性処理の連携

Last updated at Posted at 2019-03-11

ラジオボタンでの選択に応じて

特定ボタンを不活性、活性にする処理。

ラジオボタンの値の取得はfor文を利用するものもあるが

自身はこっちのほうがスッキリで好きなので記録用に。。。

index.html

<form id="testForm" method="get">
  <input type="radio" name="a" value="1" onclick="goDisabled();">不活性
  <input type="radio" name="a" value="2" onclick="goDisabled();">活性
  <input type="radio" name="a" value="3" onclick="goDisabled();">活性
</form> 
<input type="button" id="goBtn" value="GO!!" />
script.js
function goDisabled(){
  var r = $('input[name="a"]:checked').val();
  if(r == 1){
    // 1のボタンを押したとき不活性化
    $("#goBtn").attr("disabled","disabled");
  }else{
    // 1以外のボタンの時活性化
    $("#goBtn").removeAttr("disabled");
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0