function
CheckValidate()
{
for
(i=1;i<=document.frmMain.hdnMaxLine.value;i++)
{
if
(eval(
"document.frmMain.Column1_"
+i+
".value"
)==
""
)
{
alert(
'กรุณากรอกข้อมูลระดับการศึกษาด้วยค่ะ แถวที่'
+ i);
eval(
"document.frmMain.Column1_"
+i+
".focus();"
)
return
false
;
}
if
(eval(
"document.frmMain.Column2_"
+i+
".value"
)==
""
)
{
alert(
'กรุณากรอกข้อมูลชื่อย่อ ปริญญาด้วยค่ะ.. แถวที่'
+ i);
eval(
"document.frmMain.Column2_"
+i+
".focus();"
)
return
false
;
}
if
(eval(
"document.frmMain.Column3_"
+i+
".value"
)==
""
)
{
alert(
'กรุณากรอกข้อมูลสาขาวิชาเอกด้วยค่ะ..แถวที่ '
+ i);
eval(
"document.frmMain.Column3_"
+i+
".focus();"
)
return
false
;
}
if
(eval(
"document.frmMain.Column4_"
+i+
".value"
)==
""
)
{
alert(
'กรุณากรอกข้อมูล จบจากสถานศึกษาด้วยค่ะ..แถวที่ '
+ i);
eval(
"document.frmMain.Column4_"
+i+
".focus();"
)
return
false
;
}
if
(eval(
"document.frmMain.Column5_"
+i+
".value"
)==
""
)
{
alert(
'กรุณากรอกข้อมูล ปี พ.ศ.ที่จบด้วยค่ะ..แถวที่ '
+ i);
eval(
"document.frmMain.Column5_"
+i+
".focus();"
)
return
false
;
}
}
}
function
CreateSelectOption(ele)
{
var
objSelect = document.getElementById(ele);
var
Item =
new
Option(
""
,
""
);
objSelect.options[objSelect.length] = Item;
<?php
while
($objResult = mysql_fetch_array($objQuery))
{
?>
var
Item =
new
Option(
"<?php echo $objResult["
Initial_th
"];?>"
,
"<?php echo $objResult["
Qualification_id
"];?>"
);
objSelect.options[objSelect.length] = Item;
<?php
}
?>
}
function
CreateSelectOption1(ele)
{
var
objSelect = document.getElementById(ele);
var
Item =
new
Option(
""
,
""
);
objSelect.options[objSelect.length] = Item;
<?php
while
($objResult = mysql_fetch_array($query_r))
{
?>
var
Item =
new
Option(
"<?php echo $objResult["
education_level_name
"];?>"
,
"<?php echo $objResult["
education_level_id
"];?>"
);
objSelect.options[objSelect.length] = Item;
<?php
}
?>
}
function
CreateNewRow()
{
var
intLine = parseInt(document.frmMain.hdnMaxLine.value);
intLine++;
var
theTable = document.getElementById(
"tbExp"
);
var
newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID
var
newCell
newCell = newRow.insertCell(0);
newCell.id = newCell.uniqueID;
newCell.setAttribute(
"class"
,
"form-group"
);
newCell.innerHTML =
"<SELECT NAME=\"Column1_"
+intLine+
"\" ID=\"Column1_"
+intLine+
"\" class=\"form-control\"></SELECT>"
;
newCell = newRow.insertCell(1);
newCell.id = newCell.uniqueID;
newCell.setAttribute(
"class"
,
"form-group"
);
newCell.innerHTML =
"<SELECT NAME=\"Column2_"
+intLine+
"\" ID=\"Column2_"
+intLine+
"\" class=\"form-control\"></SELECT>"
;
newCell = newRow.insertCell(2);
newCell.id = newCell.uniqueID;
newCell.setAttribute(
"class"
,
"form-group"
);
newCell.innerHTML =
"<INPUT TYPE=\"TEXT\" NAME=\"Column3_"
+intLine+
"\" ID=\"Column3_"
+intLine+
"\" VALUE=\"\" autocomplete=\"off\"class=\"form-control\" >"
;
newCell = newRow.insertCell(3);
newCell.id = newCell.uniqueID;
newCell.setAttribute(
"class"
,
"form-group"
);
newCell.innerHTML =
"<INPUT TYPE=\"TEXT\" NAME=\"Column4_"
+intLine+
"\" ID=\"Column4_"
+intLine+
"\" VALUE=\"\" autocomplete=\"off\" class=\"form-control\" > "
;
newCell = newRow.insertCell(4);
newCell.id = newCell.uniqueID;
newCell.setAttribute(
"class"
,
"form-group"
);
newCell.innerHTML =
"<INPUT TYPE=\"TEXT\" NAME=\"Column5_"
+intLine+
"\" ID=\"Column5_"
+intLine+
"\" VALUE=\"\" autocomplete=\"off\" class=\"form-control\">"
;
newCell = newRow.insertCell(5);
newCell.id = newCell.uniqueID;
newCell.setAttribute(
"class"
,
"form-group"
);
newCell.innerHTML =
"<INPUT TYPE=\"hidden\" NAME=\"Column6_"
+intLine+
"\" ID=\"Column6_"
+intLine+
"\" VALUE=\"55555\" >"
;
CreateSelectOption1(
"Column1_"
+intLine)
CreateSelectOption(
"Column2_"
+intLine)
document.frmMain.hdnMaxLine.value = intLine;
}
function
RemoveRow()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
if
(parseInt(intLine) > 0)
{
theTable = document.getElementById(
"tbExp"
);
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
bamossza
พลังงานการช่วยเหลือ
( Level 3 )
( 16 )
ตอบกระทู้ ( 112 )
เขียนบทความ ( 28 )
หลังจากกดปุ่ม submit form (PHP)
$count
=
count
(
$_POST
[
"Column1"
]);
//เช็คก่อนว่ามีกี่แถว
if
(
$count
> 0){
//เช็คว่ามีข้อมูลทั้งหมดกี่แถว
for
(
$i
=0;
$i
<
$count
;
$i
++) {
$sql
= "
INSERT INTO table(Column1, Column2, Column3, Column4, Column5)
VALUES(
'{$_POST["Column1"][$i]}'
,
'{$_POST["Column2"][$i]}'
,
'{$_POST["Column3"][$i]}'
,
'{$_POST["Column4"][$i]}'
,
'{$_POST["Column5"][$i]}'
)
";
query(
$sql
);
}
//end loop
}
//end if
HTML FORM(CODE)
<input name="Column1[]" />
<input name="Column2[]" />
<input name="Column3[]" />
<input name="Column4[]" />
<input name="Column5[]" />
ลองไปประยุทธ์อีกทีครับ แบบนี้ง่ายด้วย