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,038

HOME > PHP > PHP Forum > ขอถามเรื่องการเพิ่ม radio ใน ตารางด้วย jquery ครับ radio name id


[PHP] ขอถามเรื่องการเพิ่ม radio ใน ตารางด้วย jquery ครับ radio name id

 
Topic : 081383



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



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



คือผมติดปัญหาตรง name=choice2[] และ id=choice2[] ของ radio ในตอนเพิ่มคำมันเป็นชื่อเดียวกันหมดเลย
ไม่ทราบว่าพอจะมีวิธีแก้มั้ยครับ

Code (PHP)
01.<script type="text/javascript">
02.$(function(){
03.    $("#addRow").click(function(){
04.        $("#mytbl").append($("#firsttr").clone());
05.    });
06.    $("#removeRow").click(function(){
07.        if($("#mytbl #firsttr").size()>1){
08.            $("#mytbl #firsttr:last").remove();
09.        }else{
10.            alert("ต้องมีรายการข้อมูลอย่างน้อย 1 รายการ");
11.        }
12.    });        
13.});
14.</script>
15.<table id="mytbl" border="0">
16.<tr id="firsttr">
17.<td>
18.<table width="690" border="0" align="center">
19.  <tr>
20.    <td colspan="2"><textarea name="proposition2[]"  id="proposition2[]" class="input_text" <?echo"$bg";?>></textarea></td>
21.  </tr>
22.  <tr>
23.    <td width="32" align="center" valign="top">ก.</td>
24.    <td width="652"><input type="radio" name="choice2[]" id="choice2[]" value="1">      <input type="text" name="text_choice1_2[]" id="text_choice1_2[]" class="input_text2" <?echo"$bg";?>></td>
25.  </tr>
26.  <tr>
27.    <td align="center" valign="middle">ข.</td>
28.    <td><input type="radio" name="choice2[]" id="choice2[]" value="2">      <input type="text" name="text_choice2_2[]" id="text_choice2_2[]" class="input_text2" <?echo"$bg";?>></td>
29.  </tr>
30.  <tr>
31.    <td align="center" valign="middle">ค.</td>
32.    <td><input type="radio" name="choice2[]" id="choice2[]" value="3">      <input type="text" name="text_choice3_2[]" id="text_choice3_2[]" class="input_text2" <?echo"$bg";?>></td>
33.  </tr>
34.  <tr>
35.    <td align="center" valign="middle">ง.</td>
36.    <td><input type="radio" name="choice2[]" id="choice2[]" value="4">      <input type="text" name="text_choice4_2[]" id="text_choice4_2[]" class="input_text2" <?echo"$bg";?>></td>
37.  </tr>
38.  <tr>
39.    <td align="center" valign="middle">จ.</td>
40.    <td><input type="radio" name="choice2[]" id="choice2[]" value="5">      <input type="text" name="text_choice5_2[]" id="text_choice5_2[]" class="input_text2" <?echo"$bg";?>></td>
41.  </tr>
42.</table>
43.<input name="action_2[]" type="hidden" id="action_2[]" value="none">
44.</td>
45.</tr>
46.</table>
47. 
48.<table width="500" border="0" cellspacing="0" cellpadding="0">
49.  <tr>
50.    <td>
51.    <button id="addRow" type="button">+</button> 
52.    &nbsp;
53.    <button id="removeRow" type="button">-</button>
54.    &nbsp;
55.    &nbsp;
56.    &nbsp;
57.    <button id="Submit" type="submit">Submit</button>   
58.    </td>
59.  </tr>
60.</table>




Tag : PHP, MySQL, Ajax, jQuery, CakePHP



ประวัติการแก้ไข
2012-07-22 03:41:35
2012-07-22 03:43:01
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-07-22 03:40:02 By : naya2007 View : 1205 Reply : 1
 

 

No. 1



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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

Code (ลองเอาไปประยุกต์ดูนะครับ)
001.<!DOCTYPE html >
002.<html>
003.<head>
004.<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
005.<title>Untitled Document</title>
006.<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
007.<script type="text/javascript">
008.$(function(){
009.    $(function(){
010.    $("#addRow").click(function(){
011.        $("#mytbl").append($("#firsttr").clone());
012.        var $count = 0;
013.        $count = $("#mytbl tbody").length + 1; //นับจำนวน tbody
014.        var NR ="";
015.        NR+="<tbody>";
016.        NR+="<tr>";
017.        NR+="<td width=\"32\" align=\"center\" valign=\"top\">ก.</td>";
018.        NR+="<td width=\"652\"><input type=\"radio\" name=\"choice"+$count+"[]\" id=\"choice"+$count+"[]\" value=\"1\">คำถามชุดที่"+$count+"</td>";
019.        NR+="</tr>";
020.        NR+=" <tr>";
021.        NR+=" <td align=\"center\" valign=\"middle\">ข.</td>";
022.        NR+="<td><input type=\"radio\" name=\"choice"+$count+"[]\" id=\"choice"+$count+"[]\" value=\"2\">คำถามชุดที่"+$count+"</td>";
023.        NR+="</tr>";
024.        NR+="<tr>";
025.        NR+="<td align=\"center\" valign=\"middle\">ค.</td>";
026.        NR+="<td><input type=\"radio\" name=\"choice"+$count+"[]\" id=\"choice"+$count+"[]\" value=\"3\">คำถามชุดที่"+$count+"</td>";
027.        NR+="</tr>";
028.        NR+="<tr>";
029.        NR+=" <td align=\"center\" valign=\"middle\">ง.</td>";
030.        NR+="<td><input type=\"radio\" name=\"choice"+$count+"[]\" id=\"choice"+$count+"[]\" value=\"4\">คำถามชุดที่"+$count+"</td>";
031.        NR+="</tr>";
032.        NR+="<tr>";
033.        NR+="<td align=\"center\" valign=\"middle\">จ.</td>";
034.        NR+="<td><input type=\"radio\" name=\"choice"+$count+"[]\" id=\"choice"+$count+"[]\" value=\"5\">คำถามชุดที่"+$count+"</td>";
035.        NR+="</tr>";
036.        NR+="</tbody>";
037.        $("#mytbl").append($(NR));
038.        $("#count").val($count);//เก็บค่าจำนวนชุดคำตอบลงใน hidden เพื่อนำค่าไปใช้
039.    });
040.    $("#removeRow").click(function(){
041.        if($("#mytbl #firsttr").size()>1){
042.            $("#mytbl #firsttr:last").remove();
043.        }else{
044.            alert("ต้องมีรายการข้อมูลอย่างน้อย 1 รายการ");
045.        }
046.    });
047.    });
048.});
049.</script>
050.</head>
051. 
052.<body>
053.<form action="getdata.php" method="post">
054.<table id="mytbl"  width="690" border="1">
055.<tbody>
056.  <tr>
057.    <td width="32" align="center" valign="top">ก.</td>
058.    <td width="652"><input type="radio" name="choice1[]" id="choice1[]" value="1">
059.  คำถามชุดที่1</td>
060.  </tr>
061.  <tr>
062.    <td align="center" valign="middle">ข.</td>
063.    <td><input type="radio" name="choice1[]" id="choice1[]" value="2">
064.คำถามชุดที่1</td>
065.  </tr>
066.  <tr>
067.    <td align="center" valign="middle">ค.</td>
068.    <td><input type="radio" name="choice1[]" id="choice1[]" value="3">
069.คำถามชุดที่1</td>
070.  </tr>
071.  <tr>
072.    <td align="center" valign="middle">ง.</td>
073.    <td><input type="radio" name="choice1[]" id="choice1[]" value="4">
074.คำถามชุดที่1</td>
075.  </tr>
076.  <tr>
077.    <td align="center" valign="middle">จ.</td>
078.    <td><input type="radio" name="choice1[]" id="choice1[]" value="5">
079.คำถามชุดที่1</td>
080.  </tr>
081.  </tbody>
082.</table>
083. 
084.<table width="500" border="0" cellspacing="0" cellpadding="0">
085.  <tr>
086.    <td>
087.    <button id="addRow" type="button">+</button> 
088.    &nbsp;
089.    <button id="removeRow" type="button">-</button>
090.    &nbsp;
091.    &nbsp;
092.    &nbsp;
093.    <button id="Submit" type="submit">Submit</button>
094.    <input type="hidden" name="count" id="count"></td>
095.  </tr>
096.</table>
097.</form>
098.</body>
099.</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-07-22 12:54:46 By : Krungsri
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอถามเรื่องการเพิ่ม radio ใน ตารางด้วย jquery ครับ radio name id
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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