ทำcheckbox ให้ติ๊กเลือกข้อมูลจากตารางมาโชว์ก่อนกด submit

พูดคุย แลกเปลี่ยน ปัญหา การเขียน JavaScript เครื่องมือ AJAX Web 2.0 AJAX Framework Jquery

Moderator: mindphp

lullaby
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 14/07/2016 8:31 am

ทำcheckbox ให้ติ๊กเลือกข้อมูลจากตารางมาโชว์ก่อนกด submit

โพสต์โดย lullaby » 14/07/2016 9:14 am

ที่ทำได้ตอนนี้คือต้องกดsubmitก่อนถึงจะกดcheckboxให้แสดงตารางข้อมูลที่เลือกได้
แต่ผมอยากได้แบบกดcheckboxเลือกก่อนแล้วพอกดsubmitให้มันแสดงข้อมูลออกมา

อันนี้codeที่ต้องติ๊กทีหลัง

โค้ด: เลือกทั้งหมด

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<title>SEARCH PART</title>
<style type = "text/css">
.sdsdsd {
   text-align: center;
   font-size: 36px;
   color: #FFF;
}
.bb {
   text-align: center;
   color: #FFF;
   font-size: 24px;
}
.C {
   text-align: center;
   color: #F93;
}
</style>
<script>
         function showMe (it, box)
         { var vis = (box.checked) ? "block" : "none";
         document.getElementById(it).style.display = vis;
}
</script>
</head>
<body>
<form name = "search" method = "get" action = "<?php echo $_SERVER['SCRIPT_NAME'];?>">
    <table width = "800" border = "0" align = "center">PART NO.
      <input name = "txtKeyword" type = "text" id = "txtKeyword" value = "<?php echo $_GET["txtKeyword"];?>">
      <input type = "submit" value = "Search"><br>
    
    
     <input type = "checkbox" name = "partno" value = "tbl_part" onclick = "showMe('div1', this)">Equipment<br>
     <input type = "checkbox" name = "comname" value = "tbl_laptop" onclick = "showMe('div2', this)">Laptop<br>
     <input type = "checkbox" name = "desktop" value = "tbl_desktop" onclick = "showMe('div3', this)">Desktop<br>
     <input type = "checkbox" name = "softname" value = "tbl_software" onclick = "showMe('div4', this)">Software<br>
   </table>
   
</form>
<form name="form1" method="post" action="updateall.php">
<?php
if($_GET["txtKeyword"] != "")
   {
   $objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
   $objDB = mysql_select_db("stock");
   //Search By part no.
   $strSQL = "SELECT * FROM tbl_part WHERE partno = '".$_GET["txtKeyword"]."' ";
   $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
      <p>&nbsp;</p>
   <div id = "div1" style = "display:none">
   <table width = "1260" border = "1">
      <tr>
         <th width = "20"> <div align = "center"> ID </div></th>
         <th width = "120"> <div align = "center"> Part NO. </div></th>
         <th width = "100"> <div align = "center"> Model </div></th>
         <th width = "80"> <div align = "center"> Type </div></th>
         <th width = "180"> <div align = "center"> Description </div></th>
         <th width = "100"> <div align = "center"> Serial NO. </div></th>
         <th width = "100"> <div align = "center"> PO NO. </div></th>
         <th width = "100"> <div align = "center"> Supplier </div></th>
         <th width = "100"> <div align = "center"> Store bin </div></th>
         <th width = "80"> <div align = "center"> Plant </div></th>
           <th width = "100"> <div align = "center"> Warranty </div></th>
         <th width = "100"> <div align = "center"> Status </div></th>
      </tr>
    
<?php
   while($objResult = mysql_fetch_array($objQuery))
   {
?>
      <tr>
         <td><div align = "center"><?php echo $objResult["id"];?></div></td>
         <td align = "center"><input type = "text" name = "txtpartno" size = "10" value = "<?php echo $objResult["partno"];?>"></td>
         <td align = "center"><input type = "text" name = "txtmodel" size = "10" value = "<?php echo $objResult["model"];?>"></td>
         <td align = "center"><input type = "text" name = "txttype" size = "10" value = "<?php echo $objResult["type"];?>"></td>
         <td align = "center"><input type = "text" name = "txtdescription" size = "10" value = "<?php echo $objResult["description"];?>"></td>
         <td align = "center"><input type = "text" name = "txtsn" size = "10" value = "<?php echo $objResult["sn"];?>"></td>
         <td align = "center"><input type = "text" name = "txtpo" size = "10" value = "<?php echo $objResult["po"];?>"></td>
         <td align = "center"><input type = "text" name = "txtcompaname" size = "10" value = "<?php echo $objResult["companame"];?>"></td>
         <td align = "center"><input type = "text" name = "txtbin" size = "10" value = "<?php echo $objResult["bin"];?>"></td>
         <td align = "center"><input type = "text" name = "txtplant" size = "10" value = "<?php echo $objResult["plant"];?>"></td>
         <td align = "center"><input type = "text" name = "txtwarranty" size = "10" value = "<?php echo $objResult["warranty"];?>"></td>
         <td align = "center"><input type = "text" name = "txtstatus" size = "10" value = "<?php echo $objResult["status"];?>"></td>
      </tr>
<?php
   }
?>
   </table>
   </div>
<?php
   $objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
   $objDB = mysql_select_db("stock");
   //Search By part no.
   $strSQL = "SELECT * FROM tbl_laptop WHERE comname = '".$_GET["txtKeyword"]."' ";
   $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
      <p>&nbsp;</p>
   <div id = "div2" style = "display:none">
   <table width = "1200" border = "1">
      <tr>
         <th width = "20"> <div align = "left"> ID </div></th>
         <th width = "50"> <div align = "left"> Computer Name </div></th>
         <th width = "50"> <div align = "left"> Model </div></th>
         <th width = "50"> <div align = "left"> Tag </div></th>
         <th width = "30"> <div align = "left"> Site </div></th>
         <th width = "50"> <div align = "left"> Mosuse </div></th>
         <th width = "50"> <div align = "left"> Adapter </div></th>
         <th width = "50"> <div align = "left"> Supplier </div></th>
         <th width = "30"> <div align = "left"> User </div></th>
         <th width = "50"> <div align = "left"> Position </div></th>
         <th width = "50"> <div align = "left"> Department </div></th>
         <th width = "50"> <div align = "left"> Warranty </div></th>
         <th width = "50"> <div align = "left"> Status </div></th>
      </tr> 
<?php
   while($objResult = mysql_fetch_array($objQuery))
   {
?>
      <tr>
         <td><div align = "center"><?php echo $objResult["id"];?></div></td>
         <td align = "center"><input type = "text" name = "txtcomname" size = "10" value = "<?php echo $objResult["comname"];?>"></td>
         <td align = "center"><input type = "text" name = "txtmodel" size = "10" value = "<?php echo $objResult["model"];?>"></td>
         <td align = "center"><input type = "text" name = "txttag" size = "10" value = "<?php echo $objResult["tag"];?>"></td>
         <td align = "center"><input type = "text" name = "txtsite" size = "10" value = "<?php echo $objResult["site"];?>"></td>
         <td align = "center"><input type = "text" name = "txtmouse" size = "10" value = "<?php echo $objResult["mouse"];?>"></td>
         <td align = "center"><input type = "text" name = "txtadapter" size = "10" value = "<?php echo $objResult["adapter"];?>"></td>
         <td align = "center"><input type = "text" name = "txtcompaname" size = "10" value = "<?php echo $objResult["companame"];?>"></td>
         <td align = "center"><input type = "text" name = "txtuser" size = "10" value = "<?php echo $objResult["user"];?>"></td>
         <td align = "center"><input type = "text" name = "txtposition" size = "10" value = "<?php echo $objResult["position"];?>"></td>
         <td align = "center"><input type = "text" name = "txtdepart" size = "10" value = "<?php echo $objResult["depart"];?>"></td>
         <td align = "center"><input type = "text" name = "txtwarranty" size = "10" value = "<?php echo $objResult["warranty"];?>"></td>
         <td align = "center"><input type = "text" name = "txtstatus" size = "10" value = "<?php echo $objResult["status"];?>"></td>
      </tr>
<?php
   }
?>
   </table>
   </div>
<?php
   $objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
   $objDB = mysql_select_db("stock");
   //Search By part no.
   $strSQL = "SELECT * FROM tbl_desktop WHERE desktop = '".$_GET["txtKeyword"]."' ";
   $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
      <p>&nbsp;</p>
   <div id = "div3" style="display:none">
   <table width = "1200" border = "1">
      <tr>
         <th width = "20"> <div align = "left"> ID </div></th>
         <th width = "50"> <div align = "left"> Computer Name </div></th>
         <th width = "50"> <div align = "left"> Model </div></th>
         <th width = "50"> <div align = "left"> Tag </div></th>
         <th width = "50"> <div align = "left"> Monitor </div></th>
         <th width = "50"> <div align = "left"> Site </div></th>
         <th width = "50"> <div align = "left"> Mosuse </div></th>
         <th width = "50"> <div align = "left"> Keyboard </div></th>
         <th width = "50"> <div align = "left"> Supplier </div></th>
         <th width = "50"> <div align = "left"> User </div></th>
         <th width = "50"> <div align = "left"> Position </div></th>
         <th width = "50"> <div align = "left"> Department </div></th>
         <th width = "50"> <div align = "left"> Warranty </div></th>
         <th width = "50"> <div align = "left"> Status </div></th>
      </tr>
<?php
   while($objResult = mysql_fetch_array($objQuery))
   {
?>
      <tr>
         <td><div align = "center"><?php echo $objResult["id"];?></div></td>
         <td align = "center"><input type = "text" name = "txtdesktop" size = "10" value = "<?php echo $objResult["desktop"];?>"></td>
         <td align = "center"><input type = "text" name = "txtmodel" size = "10" value = "<?php echo $objResult["model"];?>"></td>
         <td align = "center"><input type = "text" name = "txttag" size = "10" value = "<?php echo $objResult["tag"];?>"></td>
         <td align = "center"><input type = "text" name = "txtdisplay" size = "10" value = "<?php echo $objResult["display"];?>"></td>
         <td align = "center"><input type = "text" name = "txtsite" size = "10" value = "<?php echo $objResult["site"];?>"></td>
         <td align = "center"><input type = "text" name = "txtmouse" size = "10" value = "<?php echo $objResult["mouse"];?>"></td>
         <td align = "center"><input type = "text" name = "txtkeyboard" size = "10" value = "<?php echo $objResult["keyboard"];?>"></td>
         <td align = "center"><input type = "text" name = "txtcompaname" size = "10" value = "<?php echo $objResult["companame"];?>"></td>
         <td align = "center"><input type = "text" name = "txtuser" size = "10" value = "<?php echo $objResult["user"];?>"></td>
         <td align = "center"><input type = "text" name = "txtposition" size = "10" value = "<?php echo $objResult["position"];?>"></td>
         <td align = "center"><input type = "text" name = "txtdepart" size = "10" value = "<?php echo $objResult["depart"];?>"></td>
         <td align = "center"><input type = "text" name = "txtwarranty" size = "10" value = "<?php echo $objResult["warranty"];?>"></td>
         <td align = "center"><input type = "text" name = "txtstatus" size = "10" value = "<?php echo $objResult["status"];?>"></td>
      </tr>
<?php
   }
   
?>
   </table>
   </div>
<?php
   $objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
   $objDB = mysql_select_db("stock");
   //Search By part no.
   $strSQL = "SELECT * FROM tbl_software WHERE softname = '".$_GET["txtKeyword"]."' ";
   $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
      <p>&nbsp;</p>
   <div id = "div4" style = "display:none">
   <table width = "1200" border="1">
      <tr>
         <th width = "20"> <div align = "left"> ID </div></th>
         <th width = "20"> <div align = "left"> Software Name </div></th>
         <th width = "50"> <div align = "left"> Contact No. </div></th>
         <th width = "50"> <div align = "left"> Product No. </div></th>
         <th width = "50"> <div align = "left"> Serial No. </div></th>
         <th width = "50"> <div align = "left"> Description </div></th>
         <th width = "50"> <div align = "left"> Location </div></th>
         <th width = "50"> <div align = "left"> Supplier </div></th>
         <th width = "50"> <div align = "left"> Warranty </div></th>
         <th width = "50"> <div align = "left"> Status </div></th>
      </tr>
<?php
   while($objResult = mysql_fetch_array($objQuery))
   {
?>
      <tr>
         <td><div align = "center"><?php echo $objResult["id"];?></div></td>
         <td align = "center"><input type = "text" name = "txtsoftname" size = "10" value = "<?php echo $objResult["softname"];?>"></td>
         <td align = "center"><input type = "text" name = "txtcontactno" size = "10" value = "<?php echo $objResult["contactno"];?>"></td>
         <td align = "center"><input type = "text" name = "txtproductno" size = "10" value = "<?php echo $objResult["productno"];?>"></td>
         <td align = "center"><input type = "text" name = "txtsn" size = "10" value = "<?php echo $objResult["sn"];?>"></td>
         <td align = "center"><input type = "text" name = "txtdescription" size = "10" value = "<?php echo $objResult["description"];?>"></td>
         <td align = "center"><input type = "text" name = "txtlocation" size = "10" value = "<?php echo $objResult["location"];?>"></td>
         <td align = "center"><input type = "text" name = "txtcompaname" size = "10" value = "<?php echo $objResult["companame"];?>"></td>
         <td align = "center"><input type = "text" name = "txtwarranty" size = "10" value = "<?php echo $objResult["warranty"];?>"></td>
         <td align = "center"><input type = "text" name = "txtstatus" size = "10" value = "<?php echo $objResult["status"];?>"></td>
      </tr>
<?php
   }
     mysql_close($objConnect);
?>
   </table>
   </div>
   <br>
  <input type = "submit" name = "submit" value = "submit">
<?php
  }
 
  ?>
  </form>
</body>
</html>

M031
PHP Hero Member
PHP Hero Member
โพสต์: 156
ลงทะเบียนเมื่อ: 20/11/2015 9:05 am

Re: ทำcheckbox ให้ติ๊กเลือกข้อมูลจากตารางมาโชว์ก่อนกด submit

โพสต์โดย M031 » 19/07/2016 5:14 am

ลบ ออก
<script>
function showMe (it, box)
{ var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;
}
</script>

ลบ ออก
onclick = "showMe('div1', this)"
onclick = "showMe('div2', this)"
onclick = "showMe('div3', this)"
onclick = "showMe('div4', this)"

lullaby
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 14/07/2016 8:31 am

Re: ทำcheckbox ให้ติ๊กเลือกข้อมูลจากตารางมาโชว์ก่อนกด submit

โพสต์โดย lullaby » 21/07/2016 9:52 am

ก็ยังไม่ได้อ่ะครับ


  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ย้อนกลับไปยัง

ผู้ใช้งานขณะนี้

กำลังดูบอร์ดนี้: 7 และ บุคคลทั่วไป 0 ท่าน