溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - 104-1-資料庫程式設計-基礎 - 第6週-Form-Radio單一選擇
 

資訊管理系
副教授
温瑞烘


歷程檔案 Portfolio


關於我 About Me

第6週-Form-Radio單一選擇

本範例改用一個php程式來完成, 第一次呼叫時為沒有按鍵, 因此 $command會等於"", 會顯示第一個頁面
當送出按鈕時, 程式會重頭開始執行, 此時$command會等於  "送出"

<?php
 $command=$_POST["command"];
  if ($command=="") {
   echo "<html><body><center>
             <form method=post action=''>
               <input type=radio name=choice value=1>選項 1 <br>
               <input type=radio name=choice value=2>選項 2 <br>
               <input type=radio name=choice value=3>選項 3 <br>
               <input type=submit name=command value=送出>
               <input type=reset  name=command value=清除>
             </form></center></body></html>";
 }

if ($command=="送出") {
  $choice=$_POST["choice"];
  if ($choice=="") {
    echo  "請回上一頁選擇一個選項"; die();
  }
  echo "<html><body> <center>
            選項:$choice <p>
           </center></body></html>";
 }
?>

 寫一程式 就下列項目中選擇一個
  班級:四技資管三甲  四技資管三乙  四技資管三丙
  性別:男  女
  興趣:至少五選一
  喜歡的工作類型:至少五選一
  地址:text輸入框

利用javascript來檢查Radio的輸入 
<?php
  $command=$_POST["command"];
  if ($command=="") {
   echo "<html><head><title>Form - Radio 範例</title>
             <script type='text/javascript'>
              function check() {
                 if (document.getElementById('choice1').checked) return true;
                 else if(document.getElementById('choice2').checked) return true;
                 else if(document.getElementById('choice3').checked) return true;
                 alert('必須選擇一個'); return false;
              }
           </script></head><body><center>
          <form method=post action=''>
           <input type=radio id='choice1' name=choice value=1>選項 1 <br>
           <input type=radio id='choice2' name=choice value=2>選項 2 <br>
           <input type=radio id='choice3' name=choice value=3>選項 3 <br>
           <input type=submit name=command value=送出 onclick='return check() ' >
           <input type=reset  name=command value=清除>
          </form></center></body></html>";
  }

  if ($command=="送出") {
    $choice=$_POST["choice"];
    echo "<html><body><center>
            選項:$choice <p>
          </center></body></html>";
  }
?>
 

.
全部共 0則留言
登入帳號密碼代表遵守學術網路規範
 


文章分類 Labels

 


最新文章 Top10

中華科技大學數位化學習歷程 - 意見反應