2012-01-10 14 views
0

私はフォームを作成し、ユーザーに3つのオプションを与えています。彼らは自分の選択に基づいて1つだけを選択することができます、私は別のページにそれらを送信したい。だから彼らは、オプション1を選択した場合、彼らは後藤abc.html、オプション2彼らはgoto def.htmlなどなどラジオの選択に基づいてフォームの宛先を変更します。

 <form id="account" action="somepage.php"> 
     <p>Select an Option</p> 
      <input type="radio" name="group1" id="basic" checked="checked" /> 

      <input type="radio" name="group1" id="trade" /> 

      <input type="radio" name="group1" id="pro" /> 

      <button class="s_button_1 s_main_color_bgr" type="submit"><span class="s_text">Continue</span></button> 
     </form> 

[OK]を編集実際には、私たちの実際のコードを新しいコードを追加します。 我々はregister.phpページ上にあり、ユーザーに登録3つのレベル(彼らは一つだけを選ぶことができます) を提供しているので、URLが

<form id="account"> 
     <div class="s_row_3 clearfix"> 
     <p>Registration Options: choose your account type</p> 
     <label class="s_radio" for="basic"> 
      <input type="radio" name="group1" id="basic" checked="checked" value="basic.php" onclick="setLocation(this)"/> 
      <strong>Register a Basic Account</strong>&nbsp;<a rel="prettyPhoto[ajax]" href="/infopops/basic.php?ajax=true&width=100%&height=100%"><span class="info">&nbsp;</span></a> 
     </label> 
     <label for="trade"> 
      <input type="radio" name="group1" id="trade" value="trade.php" onclick="setLocation(this)"/> 
      <strong>Register a Trade Account</strong>&nbsp;<a rel="prettyPhoto[ajax]" href="/infopops/trade.php?ajax=true&width=100%&height=100%"><span class="info">&nbsp;</span></a> 
     </label></a> 
     </label> 
     <label for="pro"> 
      <input type="radio" name="group1" id="pro" value="pro.php" onclick="setLocation(this)"/> 
      <strong>Register a Pro Account</strong>&nbsp;<a rel="prettyPhoto[ajax]" href="/infopops/pro.php?ajax=true&width=100%&height=100%"><span class="info">&nbsp;</span></a> 
     </label></a> 
     </label> 
     <br /> 
     <p>By creating an account you will be able to shop faster, be up to date on an order's status, and keep track of the orders you have previously made.</p> 

     </div> 
     <span class="clear border_ddd"></span> 
     <br /> 
     <button class="s_button_1 s_main_color_bgr" type="submit"><span class="s_text">Continue</span></button> 
    </form> 

www.somedomain.com/register.php Jsとはされています

<!--form script--> 
<script type="text/javascript"> 
      function setLocation(element) { 
      document.forms[0].action = element.value 
    } 
</script> 
<!--//form script end--> 
+0

取られています。だから、なぜラジオボタンを使う必要があるのですか? – DOK

+0

@DOK - OPは 'action'属性のみを変更したいので、フォームが送信されると正しい位置に送信されます。 –

+0

フォームを送信したとき、またはラジオボタンの1つをクリックしたときに特定のページに送信する予定ですか? – j08691

答えて

2

それはjQueryを使って簡単だが、ここでは基本的なバージョンです:彼らはラジオボタンのいずれかをクリックすると、彼らはすぐに別のページに

<input type="radio" name="group1" id="basic" value="a.html" onclick="setLocation(this)" checked="checked" /> 

function setLocation(element) { 
     document.forms[0].action = element.value 
} 
+0

jbleryを盲目的に使用しないための+1。 –

+0

を変更する必要がありますか?すなわち、アクションを取り除く?私はこれを今実行していて、どんな喜びも得ていません。 – 422

+0

ok、ほぼ...そのような解析URL:group1 = b.html – 422

関連する問題