2012-04-18 31 views
-1

私はクライアント用に構築しているフォームを持っています。ラジオボタンの1つのグループが選択されているときにチェックを入れようとしていますが、チェックボックスが選択されている場合、他のラジオボタンが選択されている場合はクリアされます。 > フォームラジオボタングループを無効/有効にする

<form action="#"> 
<fieldset><legend>Activities</legend> 
    <input style="margin-right:0; margin-left:0;" type="radio" id="Golf" value="I would like to golf at The Breakers Ocean Course" name="activity" /> 
    <label for="Golf">Golf - The Breakers Ocean Course</label> 
    <ul style="margin-top:0;"> 
     <label for="club">Club Rental</label> 
     <input style="margin-right:0; margin-left:0;" type="radio" id="club-yes" value="Yes" name="clubrental" /> 
     <label for="club-yes">Yes</label> 
     or 
     <input style="margin-right:0; margin-left:0;" type="radio" id="club-no" value="No" name="clubrental" /> 
     <label for="club-no">No</label><br> 

     <input style="margin-right:0; margin-left:0;" type="radio" id="right-hand" value="Right Handed" name="clubhand" /> 
     <label for="right-hand">Right Handed</label> 
     or 
     <input style="margin-right:0; margin-left:0;" type="radio" id="left-hand" value="Left Handed" name="clubhand" /> 
     <label for="left-hand">Left Handed</label> 
    </ul> 
<div style="clear:both;">&nbsp;</div> 
    <input style="margin-right:0; margin-left:0;" type="radio" id="hometour" value="I would like to take the Home tour and Worth Avenue Shopping" name="activity" /> 
    <label for="hometour">Home tour and Worth Avenue Shopping</label> 
<div style="clear:both;">&nbsp;</div> 
    <input style="margin-right:0; margin-left:0;" type="radio" id="museum" value="I would like to attend the Cars of Dreams Museum Tour" name="activity" /> 
    <label for="museum">Cars of Dreams Museum Tour</label> 
<div style="clear:both;">&nbsp;</div> 
    <input style="margin-right:0; margin-left:0;" type="radio" id="spa" value="I would like to attend The Spa at the Breakers" name="activity" /> 
    <label for="spa">Spa - The Spa at the Breakers</label> 
     <ul style="margin-top:5px;"> 
      - Please select two treatments<br> 
      <div style="float:left; width:220px; margin-right:15px;"> 
      <input type="checkbox" id="personal-retreat-massage" value="Personal Retreat Massage" name="treatment" onclick="setItems(this)"> 
      <label for="personal-retreat-massage">Personal Retreat Massage</label> 
      </div> 
      <div style="float:left; width:220px; margin-right:15px;"> 
      <input type="checkbox" id="simplicity-massage" value="Simplicity Massage" name="treatment" onclick="setItems(this)"> 
      <label for="simplicity-massage">Simplicity Massage</label> 
      </div> 
      <div style="float:left; width:220px; margin-right:15px;"> 
      <input type="checkbox" id="guerlain-classic-facial" value="Guerlain Classic Facial" name="treatment" onclick="setItems(this)"> 
      <label for="guerlain-classic-facial">Guerlain Classic Facial</label> 
      </div> 
      <div style="float:left; width:220px; margin-right:15px;"> 
      <input type="checkbox" id="cellular-enzyme-peel" value="Cellular Enzyme Peel" name="treatment" onclick="setItems(this)"> 
      <label for="cellular-enzyme-peel">Cellular Enzyme Peel</label> 
      </div> 
     </ul> 
</fieldset> 
    <center><input style="width:75px; height:25px; margin-bottom:25px;" type="submit" value="Submit" name="submit"></center> 
</form 

を私はこれが唯一のJavascriptをすることができ、PHPを使用することはできません。ここで

は、私が使用していたコードです。

ありがとうございます。

+0

あなたが試したことを投稿すると、これに対する返答が増えるかもしれません。あなたはおそらく、あなたの現在の問題に影響を与えるあなたのhtmlのビットだけを投稿してもいいですか? – Andbdrew

答えて

0

スパムラジオボタンが選択されていないときにチェックボックスを無効にし、選択したときに有効にしてみます。無線要素の焦点の状態を確認することができます。私は次のようなものがあなたにとってうまくいくはずだと考えています:

$('[type="radio"]').focus(function(){ 
    if ($('#spa').prop('checked')) {// jQuery 1.7.2 
     $('[type="checkbox"]').removeAttr('disabled'); 
    } else { 
     $('[type="checkbox"]').attr('disabled', 'disabled'); 
    } 
}) 

希望します!

jQueryドキュメントをチェックしてください。彼らはとても役に立ちます!

http://api.jquery.com/

あなたの現在の状況に役立つかもしれないいくつかのものがあります:

http://api.jquery.com/attr/

http://api.jquery.com/removeAttr/

http://api.jquery.com/focus/

http://api.jquery.com/blur/

http://api.jquery.com/category/selectors/

関連する問題