はじめまして。
以下のようなラジオボタンに対し、選択肢1に対するチェック状態をtrueにするようなjavaScript
を実装したいと考えています。
xhtml
1<h:inputHidden> 2 <f:viewParam name="select" value="#{SomeBean.select}" id="select"/> 3</h:inputHidden> 4<span class="label-txt"> 5 <div class="radio"> 6 <input id="1" name="select" class="radio__input" type="radio" value="0" /> 7 <label for="1" class="checkbox" ><span class="image"></span>選択肢1</label> 8 <input id="2" name="select" class="radio__input" type="radio" value="1" /> 9 <label for="2" class="checkbox"><span class="image"></span>選択肢2</label> 10 </div> 11</span>
現在のところ、下記のようなjavascriptを実装していますが、実行しても
うまくチェック状態になってくれません。
javascript
1 function writeKoumoku() { 2//試したもの1 3document.getElementById("1").checked = true; 4//試したもの2 5$('#1').prop('checked',true); 6}
トリガーとなるボタンは以下のように実装しています。
xhtml
1<input type="button" class="button grid-09-px button__function button__function--slim" value="打鍵補助用スクリプトの実行" onclick="writeKoumoku()"/>
どなたか知識のある方、選択肢1の状態をcheckedにするjavascriptの実装方法をご教授ください。
■追記
⇒上記のxhtml内にボタンを配置し、押下時にonclick属性でjavaScriptを実行し、チェック状態にしたいと考えています。
よろしくお願いします。