Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยแนะนำทีครับ เกี่ยวกับ select checkbox all และการ show/hide textbox ครับ



 

ช่วยแนะนำทีครับ เกี่ยวกับ select checkbox all และการ show/hide textbox ครับ

 



Topic : 076337



โพสกระทู้ ( 350 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



คือผมได้ใส่โค้ด check all เพิ่มเติมลงไป ซึ่งแต่เดิมจะใช้การกดทีละตัวเลือก ซึ่งบางตัวเลือกจะมี active ให้แสดง textbox ที่ซ๋อนอยู่ด้วย
ด้วยการใช้ onclick ควบคุม แต่ติดปัญหาที่ว่า พอใช้ check all มันได้แค่ทำการเช็คเท่านั้นครับ แต่ textbox ที่ซ่อนไม่แสดง

1

ต้องติกออกแล้ว ติกเช็คใหม่เฉพาะช่องนั้น ถึงจะแสดง textbox ออกมาครับ
เลยอยากจะรุ้ว่า จะแก้ยังไงดีครับ ที่จะให้มันแสดงได้ทันทีที่มีการ ติก

2



Tag : PHP, MySQL, HTML/CSS, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-29 14:21:11 By : akkaneetha View : 1427 Reply : 3
 

 

No. 1



โพสกระทู้ ( 648 )
บทความ ( 0 )



สถานะออฟไลน์


ต้องดูที่เงื่อนไขของฟังก์ชันครับ

ลองเอาโค้ดมาแปะดูครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-29 14:30:18 By : 50121680
 


 

No. 2



โพสกระทู้ ( 350 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>: : Preventive &amp; Maintenance Node : :</title>
<script language="javascript">
function fncShowHideInput(value) {
var input1 = document.getElementById('v_AC');
if(value.checked) {input1.style.display='';}
else{input1.style.display='none';}
}
//////////////////////////
function fncShowHideInput2(value2) {
var input2 = document.getElementById('v_DC');
if(value2.checked) {input2.style.display='';}
else{input2.style.display='none';}
}
/////////////////////////
function fncShowHideInput3(value3) {
var input3 = document.getElementById('batt');
if(value3.checked) {input3.style.display='';}
else{input3.style.display='none';}
}
</script>
<script language = "JavaScript">
function Listnode(SelectValue)
		{
			form1.node.length = 0
			<?
			$intRows = 0;
			$strSQLm = "SELECT * FROM  pm ORDER BY node_H ASC";
			$objQuerym = mysql_query($strSQLm) or die ("Error Query [".$strSQLm."]");
			$intRows = 0;
			while($objResultm = mysql_fetch_array($objQuerym))
			{
			$intRows++;
			?>
				x = <?=$intRows;?>;
				mySubList = new Array();
				strGroup = <?=$objResultm["id"];?>;
				strValue = "<?=$objResultm["location"];?>";
				strItem = "<?=$objResultm["location"];?>";
				mySubList[x,0] = strItem;
				mySubList[x,1] = strGroup;
				mySubList[x,2] = strValue;		
				if (mySubList[x,1] == SelectValue){
					var myOption = new Option(mySubList[x,0], mySubList[x,2])  
					form1.node.options[form1.node.length]= myOption					
				}
			<?
			}
			?>																	
		}
</script>
<link rel="stylesheet" type="text/css" href="../../Scripts/epoch_styles.css"/>
<script type="text/javascript" src="../../Scripts/epoch_classes.js">//***Calendar****//</script>
<script type="text/javascript">
var calendar;
window.onload = function() {
calendar = new Epoch('cal2','popup',document.getElementById('calendar_container'),false);	
};
//***end Calendar***//
</script>
<script language=JavaScript type=text/javascript>
<!-- 
function CheckAll() {
for (var i = 0; i < document.form1.elements.length; i++) {
if(document.form1.elements[i].type == 'checkbox'){
document.form1.elements[i].checked = !(document.form1.elements[i].checked);
}
}
}
//-->
</script>
<style type="text/css">
<!--
.style12 {font-size: 12px; font-weight: bold; color: #666666; }
.style2 {font-weight: bold; font-size: 24px;}
.style13 {font-size: 12px}
.style14 {color: #FFFFFF}
.style15 {font-size: 14px}
.style19 {color: #FFFFFF; font-weight: bold; font-size: 12px; }
.style20 {color: #999999}
.style21 {font-weight: bold; font-size: 36px; }
a:link {
	color: #FFFFFF;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #FFFFFF;
}
a:hover {
	text-decoration: none;
	color: #00FF00;
}
a:active {
	text-decoration: none;
}
-->
</style>
</head>
<body>
<script language="javascript">
function fncSubmit()
{
	if(document.form1.date.value == "")
	{
		alert('กรุณาใส่วันที่');
		document.form1.date.focus();		
		return false;
	}	
	if(document.form1.location.value == "")
	{
		alert('กรุณาเลือก Location ');
		document.form1.location.focus();
		return false;
	}	
	if(document.form1.node.value == "")
	{
		alert('กรุณาเลือก node');
		document.form1.node.focus();		
		return false;
	}	
	document.form1.submit();
}
</script>
<form id="form1" name="form1" method="post" action="savePM.php" OnSubmit="return fncSubmit();">
  <table width="613" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#333333">
    <tr>
      <td width="50">&nbsp;</td>
      <td width="170" align="right"><span class="style19">ID</span></td>
      <td width="170"><input name="UserID" type="text" id="UserID" value="<?php echo $objResult['UserID'];?>" size="7" readonly="true" autocomplete="off"/></td>
      <td width="50">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><span class="style19">วันที่</span></td>
      <td><input type="text" name="date" id="calendar_container" style="width:80px" autocomplete="off" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><span class="style1"><span class="style19">Locations</span></span></td>
      <td><span class="style1">
        <select  id="location" name="location" style="width:170px" onchange="Listnode(this.value)">
          <option selected="selected" value=""></option>
          <?php
$strSQLm = "SELECT * FROM pm ORDER BY node_H";
$objQuerym = mysql_query($strSQLm)or die("Error Query [".$strSQLm."]");
	while($objResultm = mysql_fetch_array($objQuerym))
	{
			?>
          <option value="<?=$objResultm["id"];?>">
          <?=$objResultm["node_H"];?>
            |
  <?=$objResultm["location"];?>
          </option>
          <?
	}
?>
        </select>
      </span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><span class="style19">Node Name</span></td>
      <td><select name="node" id="node" style="width:170px">
      </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><label></label></td>
      <td align="right"><span class="style19">ผู้ปฏิบัติงาน 1</span></td>
      <td><input name="worker1" type="text" id="worker1" style="width:170px" value="<?php echo $objResult["fname"];?>" readonly="true" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><span class="style19">ผู้ปฏิบัติงาน 2</span></td>
      <td><select name="worker2" id="worker2" style="width:170px">
        <option selected="selected"></option>
        <?
				$mem2SQL = "SELECT fname FROM members";
				$mem2Query = mysql_query($mem2SQL);
                while($mem2Result = mysql_fetch_array($mem2Query))
				{
				?>
        <option value="<?=$mem2Result["fname"];?>">
        <?=$mem2Result["fname"];?>
        </option>
        <?
				}
				?>
      </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="4" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#FF0000"><input type="button" name="Button" value="Select All" onClick=CheckAll();></td>
      <td bgcolor="#FF0000">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#FF0000"><span class="style8 style14 style15"><strong>ระบบ Power</strong></span></td>
      <td bgcolor="#FF0000"><span class="style8 style14 style15"><strong>ระบบระบายอากาศ</strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="power1" type="checkbox" id="power1" value="1" />
          meter main AC </label>
      </strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style13 style3"><strong>
        <label>
        <input name="Air1" type="checkbox" id="Air1" value="1" />
          พัดลมฝาตู้ </label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="power2" type="checkbox" id="power2" onclick="JavaScript:fncShowHideInput(this);" />
          Volt AC</label>
        <label>
        <input name="v_AC" type="text" id="v_AC" style="width:50px; display:none" autocomplete="off" />
        </label>
        (v)</strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style13 style3"><strong>
        <label>
        <input name="Air2" type="checkbox" id="Air2" value="1" />
          พัดลมฝาบน</label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="power3" type="checkbox" id="power3" onclick="JavaScript:fncShowHideInput2(this);"/>
          Volt DC</label>
        <input type="text" name="v_DC" id="v_DC" style="width:50px; display:none" autocomplete="off" />
        (v)</strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style13 style3"><strong>
        <label>
        <input name="Air3" type="checkbox" id="Air3" value="1" />
          พัดลม Node</label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="power4" type="checkbox" id="power4" value="1" />
          Breaker (AC)</label>
      </strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style13 style3"><strong>
        <label>
        <input name="Air4" type="checkbox" id="Air4" value="1" />
          แผ่น Filter </label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="power5" type="checkbox" id="power5" value="1" />
          Breaker (DC)</label>
      </strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style13 style3"><strong>
        <label>
        <input name="Air5" type="checkbox" id="Air5" value="1" />
          เป่า ทำความสะอาด</label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="power6" type="checkbox" id="power6" onclick="JavaScript:fncShowHideInput3(this);" />
          Battery</label>
        <input type="text" name="batt" id="batt" style="width:50px; display:none" autocomplete="off"/>
        (v)</strong></span></td>
      <td bgcolor="#CCCCCC">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#FF0000"><span class="style14 style8 style15"><strong>ตอนนอก</strong></span></td>
      <td bgcolor="#FF0000"><span class="style8 style14 style15"><strong>สภาพทั่วไป</strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="outside1" type="checkbox" id="outside1" value="1" />
          Jumper</label>
      </strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="other1" type="checkbox" id="other1" value="1" />
          ตู้ Node</label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="outside2" type="checkbox" id="outside2" value="1" />
          แผงตอนนอก + กันฟ้า</label>
      </strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="other2" type="checkbox" id="other2" value="1" />
          OFC</label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="outside3" type="checkbox" id="outside3" value="1" />
          รู Cable</label>
      </strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="other3" type="checkbox" id="other3" value="1" />
          Patch Cord</label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="outside4" type="checkbox" id="outside4" value="1" />
          Ground</label>
      </strong></span></td>
      <td bgcolor="#CCCCCC"><span class="style3 style13"><strong>
        <label>
        <input name="other4" type="checkbox" id="other4" value="1" />
          Label</label>
      </strong></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><label></label><label></label></td>
      <td colspan="2" bgcolor="#FF0000"><span class="style19">หมายเหตุ</span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2" bgcolor="#CCCCCC"><label>
        <textarea name="note" id="note" style="width:480px; height:50px "></textarea>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="4" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="4" align="center"><label>
        <input type="submit" name="button" id="button" value="ยืนยันการเพิ่มข้อมูล" onclick="return confirm('ยืนยันการเพิ่มข้อมูล')" />
      </label>
        <label>
        <input type="reset" name="button2" id="button2" value="ล้าง" />
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-29 14:46:34 By : akkaneetha
 

 

No. 3



โพสกระทู้ ( 648 )
บทความ ( 0 )



สถานะออฟไลน์


คุณบอกว่า กด Select All แล้ว Textbox ไม่มา งั้นก็แสดงว่าเป็นที่ ฟังก์ชัน CheckAll()
Code (PHP)
function CheckAll() {
 for (var i = 0; i < document.form1.elements.length; i++) {
  if(document.form1.elements[i].type == 'checkbox'){
   document.form1.elements[i].checked = !(document.form1.elements[i].checked);
  }
 }
}


คุณก็แค่เพิ่ม
Code (PHP)
input1.style.display='';
input2.style.display='';
input3.style.display='';

ลงในฟังก์ชัน CheckAll()

หรือจะลองเขียนเป็นลูป คล้าย Checkbox ก็ได้ครับ


ประวัติการแก้ไข
2012-03-29 15:35:52
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-29 15:34:54 By : 50121680
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยแนะนำทีครับ เกี่ยวกับ select checkbox all และการ show/hide textbox ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่