ขอCode ตรวจข้อสอบทางweb หน่อยคับ แบบ Choice
ผมมีแนวคับ ใครต่อยอดได้ ช่วยทีคับ
public String cerateChoices(){ //if(type==..... int max_choice = 5; String choices = ""; for(int i=0;i<max_choice;i++){ choices += createChoice(i); } return choices; } //String s="1,2" --> String ar[] = s.split(","); private String getEachChoice(int index){ String ch=""; switch(index){ case 0 : ch=getC1(); break; //ค่าในdatabase ไม่ออก case 1 : ch=getC2(); break; case 2 : ch=getC3(); break; case 3 : ch=getC4(); break; case 4 : ch=getC5(); break; //... } return ch; } private String createChoice(int index){ String ch= " <tr>" + "<td valign=\"top\" bgcolor=\"#F3F9DF\" class=\"HI\"><table width=\"641\" border=\"0\" align=\"left\">" + "<tr>" + "<td width=\"26\"><input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\" value=\"" + index +"\" " + isSel(index) + " />" + "</td>" + "<td width=\"645\" valign=\"middle\" align=\"left\">" + getEachChoice(index) + "</td>" + "</tr>"; return ch; } public String isSel(int index){ String result=""; if(selected[index]==true) result = "selected"; return result; }
|