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 > ต้องการให้ checkbox กับ radio enabled ถ้า textbox มีข้อมูลอยู่



 

ต้องการให้ checkbox กับ radio enabled ถ้า textbox มีข้อมูลอยู่

 



Topic : 102818



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



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



ตอนนี้ผมใช้วิธี Disabled checkbox และ radio ไว้ ถ้าไม่มีการกรอกข้อมูลลงใน Textbox แต่ถ้ามีการกรอกข้อมูลใน Textbox ทั้งสองอย่างนั้นจะเปิดให้ user สามารถเลือกได้ ซึ่งไม่มีปัญหาอะไร แต่พอย้อนกลับไปแก้ไขค่ามันออกมาครับ แต่ว่ามัน Disabled ไว้ พอมีวิธีที่ทำให้มัน enabled ทันทีที่ query ข้อมูลออกมาไหมครับ

Code (PHP)
Code (JavaScript)
<script language="JavaScript">
		function fncEnabled_other1()
		{
			document.getElementById('q1a_11').disabled = false;
			document.getElementById('q1b_11').disabled = false;
			document.getElementById('q2_11').disabled = false;
		}
		function fncEnabled_other2()
		{
			document.getElementById('q1a_12').disabled = false;
			document.getElementById('q1b_12').disabled = false;
			document.getElementById('q2_12').disabled = false;
		}

</script>	

Code (PHP)
		  <form class="rnd5" action="" method="post" name="form1" onSubmit="return check(this)" >
			<div class="form-input clear">			  
			<table>
				<thead>
				  <tr id="q1">
					<th>Question / Brands</th>
					<th>Apple</th>
					<th width="7%">Blackberry</th>
					<th>HTC</th>
					<th width="7%">i-mobile</th>
					<th>LG</th>
					<th>Nokia</th>
					<th>Oppo</th>
					<th>Samsung</th>
					<th>Sony</th>
					<th width="8%">TriNet (dtac)</th>
					<th>อื่นๆ ระบุ <input name="other1" type="text" size="5" value=" <?php echo $result1['q1_other1'];?>" OnKeyDown="fncEnabled_other1()"></th>
					<th>อื่นๆ ระบุ <input name="other2" type="text" size="5" value=" <?php echo $result1['q1_other2'];?>" OnKeyDown="fncEnabled_other2()"></th>
				  </tr>
				</thead>
				<tbody>
				  <tr id="q1"  class="light">
					<td>Q1a เมื่อพูดถึงโทรศัพท์สมาร์ทโฟน มีแบรนด์ไหนบ้างที่คุณรู้จัก (คำตอบเดียว เอ่ยครั้งแรก)</td>
					<td><center><input name="q1a" type="radio" value="1" <? if($result1['q1a'] == 1){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="2" <? if($result1['q1a'] == 2){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="3" <? if($result1['q1a'] == 3){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="4" <? if($result1['q1a'] == 4){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="5" <? if($result1['q1a'] == 5){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="6" <? if($result1['q1a'] == 6){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="7" <? if($result1['q1a'] == 7){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="8" <? if($result1['q1a'] == 8){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="9" <? if($result1['q1a'] == 9){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="10" <? if($result1['q1a'] == 10){echo 'checked';}?> ></center></td>
					<td><center><input name="q1a" type="radio" value="11" <? if($result1['q1a'] == 11){echo 'checked';}?> id="q1a_11" disabled="disabled" ></center></td>
					<td><center><input name="q1a" type="radio" value="12" <? if($result1['q1a'] == 12){echo 'checked';}?> id="q1a_12" disabled="disabled" ></center></td>
				  </tr>
				  <tr id="q1" class="dark">
					<td>Q1b มีแบรนด์ไหนอีกไหมครับ/ค่ะ (ให้ผู้ตอบแบบสอบถามเอ่ยเพิ่มเติม)</td>
					<td><center><input name="q1b_1" type="checkbox" value="1" <? if($result1['q1b_1'] == 1){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_2" type="checkbox" value="2" <? if($result1['q1b_2'] == 2){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_3" type="checkbox" value="3" <? if($result1['q1b_3'] == 3){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_4" type="checkbox" value="4" <? if($result1['q1b_4'] == 4){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_5" type="checkbox" value="5" <? if($result1['q1b_5'] == 5){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_6" type="checkbox" value="6" <? if($result1['q1b_6'] == 6){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_7" type="checkbox" value="7" <? if($result1['q1b_7'] == 7){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_8" type="checkbox" value="8" <? if($result1['q1b_8'] == 8){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_9" type="checkbox" value="9" <? if($result1['q1b_9'] == 9){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_10" type="checkbox" value="10" <? if($result1['q1b_10'] == 10){echo 'checked';}?> ></center></td>
					<td><center><input name="q1b_11" type="checkbox" value="11" <? if($result1['q1b_11'] == 11){echo 'checked';}?> id="q1b_11" disabled="disabled" ></center></td>
					<td><center><input name="q1b_12" type="checkbox" value="12" <? if($result1['q1b_12'] == 12){echo 'checked';}?> id="q1b_12" disabled="disabled"></center></td>				  
				  </tr>
				  
				  <tr id="q2" class="light">
					<td>Q2 โทรศัพท์สมาร์ทโฟนแบรนด์ไหนบ้างครับ/ค่ะ ที่คุณสนใจสืบค้นข้อมูลเพื่อหาความรู้ เช่นความเป็นมา จุดเด่น จุดด้อย ราคา แหล่งจำหน่าย (ตอบได้หลายคำตอบ) </td>
					<td><center><input name="q2_1" type="checkbox" value="1" <? if($result['q2_1'] == 1){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_2" type="checkbox" value="2" <? if($result['q2_2'] == 2){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_3" type="checkbox" value="3" <? if($result['q2_3'] == 3){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_4" type="checkbox" value="4" <? if($result['q2_4'] == 4){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_5" type="checkbox" value="5" <? if($result['q2_5'] == 5){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_6" type="checkbox" value="6" <? if($result['q2_6'] == 6){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_7" type="checkbox" value="7" <? if($result['q2_7'] == 7){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_8" type="checkbox" value="8" <? if($result['q2_8'] == 8){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_9" type="checkbox" value="9" <? if($result['q2_9'] == 9){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_10" type="checkbox" value="10" <? if($result['q2_10'] == 10){echo 'checked';}?> ></center></td>
					<td><center><input name="q2_11" type="checkbox" value="11" <? if($result['q2_11'] == 11){echo 'checked';}?> id="q2_11" disabled="disabled" ></center></td>
					<td><center><input name="q2_12" type="checkbox" value="12" <? if($result['q2_12'] == 12){echo 'checked';}?> id="q2_12" disabled="disabled" ></center></td>				  
					</tr>
				</tbody>
			  </table>
			</div>
			<p>
			  <input type="submit" id_que="Submit" onClick="CheckCheckboxes()">
			  &nbsp;
			  <input type="reset" value="Reset">
			</p>
		  </form>




Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-11-19 12:58:05 By : flintstone View : 1204 Reply : 4
 

 

No. 1

Guest


ถ้า เอาแบบง่ายๆ โง่ๆ แบบผมนะครับ

ผมก็เขียน function javascript check ค่า แล้วสั่งให้ enable disable แล้วก็เรียก function นี้ ตอน onload

ปล. นี่ความคิดส่วนตัวนะครับ ผิดพลาดยังไงขออภัยด้วย






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-19 13:17:43 By : gumix
 


 

No. 2



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



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

ไม่มีผลใดๆครับ เกี่ยวกับที่ผมตั้ง onKeyDown หรือเปล่า
ตอนนี้ผมลองเอา if คลุมตรง Disabled ให้เช็คค่าว่างจาก textbox ก็กลายเป็นว่า function ไม่สามารถใช้งาน
ใครมีวิธีไหนอีกไหมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-19 13:31:41 By : flintstone
 

 

No. 3

Guest


งง เหมือนกัน

ถ้า ผมเขียน function javascript


function checkData(){

if(document.getElementById('other1').value != ""){ // หรือ if( "<?=$result1['q1_other1']" != "")
fncEnabled_other1();

}
if(document.getElementById('other2').value != ""){ // หรือ if( "<?=$result1['q1_other2']" != "")
fncEnabled_other2();

}

}

ส่วน html <body onload="checkData()">

งี้ไม่ได้เหร๋อคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-19 13:46:19 By : gumix
 


 

No. 4



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



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

ได้แล้วครับ ขอบคุณมากครับ
ผมยังอ่อนเรื่อง java script อยู่ ดันเอาเงื่อนไขไปใส่ในฟังก์ชั่นเก่า มันเลยไม้ได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-19 14:04:43 By : flintstone
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการให้ checkbox กับ radio enabled ถ้า 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 04
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 อัตราราคา คลิกที่นี่