테스트 사이트 - 개발 중인 베타 버전입니다

php 화면 이동 없이 라디오버튼 값 받기 채택완료

Sssuj 4년 전 조회 3,309

라디오 버튼으로 항목을 선택한 후 선택완료 버튼을 클릭하면 화면의 이동없이 php 변수에 라디오 버튼의 값을 저장하고 싶습니다. 어떤 방법을 써야하나요?

 

개인적으로 생각해본 방법은 php문서로 이동은 하지만 $check=$_POST['check']; 이런식으로 받은 값을 그대로 다시 돌려보내면서 바로 1번 페이지로 돌아오게 하여 사용자에게 보이지 않고 php 상에서는 값을 전달받고 다시 전달하는 방식을 생각해보았는데 실현할 수 있는지도 궁금합니다.

 

</strong></p>

<p><body>

   <div class="nav_tori">

      <span>Tori</span>

      <span>Date</span>

   </div></p>

<p>   <div class="explanation">대회를 선택해주세요.</div>

   <form name="titleForm" class="titleForm" method="post" action="mergeIMG.php" style="width:450px; height:310px;">

      <center>

      

   <div style="width:440px; height:300px; overflow:auto; display: block;">

      <table class="titleTable" width="420">

         <thead>

         <tr class="tableTop">

            <th scope="cols">대회 리스트</th>

            <th scope="cols"></th>

         </tr>

         </thead>

         <tbody>

<?php

   $conn = mysqli_connect("localhost", "lsj", "1234" , "phptest");

   $sql = "SELECT id, passwd FROM member";

   $result = mysqli_query($conn, $sql);

   $cnt = 0; //타이틀 행 갯수

   if (mysqli_num_rows($result) > 0){

   while ($row = mysqli_fetch_array($result)){

      if($cnt%2==0){ //cnt가 짝수인 경우 배경을 흰색으로

         ?>

            <tr>

               <th scope="row" class="h"><?=$row[0]?></th>

               <th class="h radio_r"><input type="radio" name="check" id="check" value="<?= $cnt ?>"/></th>

            </tr>

         <?php

      }else{

         ?>

            <tr>

               <th scope="row" class="even"><?=$row[0]?></th>

               <th class="even radio_r"><input type="radio" name="check" id="check" value="<?= $cnt ?>"/></th>

            </tr>

         <?php

      }

      $cnt++;

?></p>

<p><?php

   }

   }else{

   echo "테이블에 데이터가 없습니다.";

   }

   mysqli_close($conn); // 디비 접속 닫기

?>

           </tbody>

         </table>

      </div>

      <p><input type="submit" value="선택완료" class="button" onclick="sendIndex(this.form);"></p>

      </center>

   </form></p>

<p><strong>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
4년 전

ajax를 활용하세요.

 

https://blex.me/@baealex/php%EC%97%90%EC%84%9C-ajax-%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95

 

관련 예제코드는 위 링크를 확인하세요.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인