Code (SQL)$sql_r="SELECT * FROM education_level_types ORDER BY education_level_id ASC ";
$query_r=mysql_query($sql_r);
$strSQL = "SELECT * FROM qualification_types ORDER BY qualification_id ASC";
$objQuery = mysql_query($strSQL);
Code (JS)function CheckValidate()
{
for(i=1;i<=document.frmMain.hdnMaxLine.value;i++)
{
//*** Column 1 ***/
if(eval("document.frmMain.Column1_"+i+".value")=="")
{
alert('กรุณากรอกข้อมูลระดับการศึกษาด้วยค่ะ แถวที่' + i);
eval("document.frmMain.Column1_"+i+".focus();")
return false;
}
//*** Column 2 ***/
if(eval("document.frmMain.Column2_"+i+".value")=="")
{
alert('กรุณากรอกข้อมูลชื่อย่อ ปริญญาด้วยค่ะ.. แถวที่' + i);
eval("document.frmMain.Column2_"+i+".focus();")
return false;
}
//*** Column 3 ***/
if(eval("document.frmMain.Column3_"+i+".value")=="")
{
alert('กรุณากรอกข้อมูลสาขาวิชาเอกด้วยค่ะ..แถวที่ ' + i);
eval("document.frmMain.Column3_"+i+".focus();")
return false;
}
//*** Column 4 ***/
if(eval("document.frmMain.Column4_"+i+".value")=="")
{
alert('กรุณากรอกข้อมูล จบจากสถานศึกษาด้วยค่ะ..แถวที่ ' + i);
eval("document.frmMain.Column4_"+i+".focus();")
return false;
}
//*** Column 5 ***/
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
//*** Column 1 ***//
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>";
//*** Column 2 ***//
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>";
//*** Column 3 ***//
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\" >";
//*** Column 4 ***//
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\" > ";
//*** Column 5 ***//
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\">";
//*** Column 5 ***//
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\" >";
//*** Create Option ***//
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;
}
}
Code (CODE)<section class="content-header">
<!-- Nav tabs -->
<div class="list-group">
<a href="#" class="list-group-item active"><i class="glyphicon glyphicon-education
"></i> บันทึกประวัติการศึกษา</a>
<a href="#"onclick="alert('กรุณาบันทึกข้อมูลประวัติการศึกษาก่อนค่ะ');" class="list-group-item "><i class="glyphicon glyphicon-th-list
"></i> รายละเอียดประวัติการศึกษา</a>
<a href="../form_add_per/index.php" class="list-group-item ">
<i class="glyphicon glyphicon-user
"></i> บันทึกประวัติส่วนตัว
</a>
</div>
</section>
<div class="container-fulid" >
<div class="panel panel-default">
<div class="panel-heading">
<h3><i class="glyphicon glyphicon-education"></i> บันทึกประวัติการศึกษา</h3>
</div>
<div class="panel-body">
<div class="container-fulid">
<form name="frmMain" action="detail.php" method="get" OnSubmit="return CheckValidate();">
<input type="hidden" name="hdnMaxLine" value="0">
<button name="btnAdd" type="button" id="btnAdd" onClick="CreateNewRow();" class="btn btn-primary"><i class="glyphicon glyphicon-plus"></i> เพิ่ม</button>
<button name="btnDel" type="button" id="btnDel" onClick="RemoveRow();" class="btn btn-danger"><i class="glyphicon glyphicon-minus"></i> ลบ</button>
<div class="table-responsive">
<table class="table" id="tbExp">
<thead>
<tr >
<th>ระดับการศึกษา</th>
<th>ชื่อย่อ ปริญญา</th>
<th>สาขาวิชาเอก</th>
<th>จบจากสถานศึกษา</th>
<th>ปี พ.ศ.ที่จบ</th>
</tr>
</thead>
<tr>
</tr>
</table>
</div>
<div class="container-fuid">
<div class="row">
<div class="col-md-3 col-md-push-3">
<div class="row"></div>
<button type="submit" class="btn btn-block btn-success" ><i class="glyphicon glyphicon-floppy-disk"></i> บันทึก</button></div>
<div class="col-md-3 col-md-push-3">
<button type="reset" class="btn btn-block btn-danger" ><i class="glyphicon glyphicon-floppy-remove"></i> ล้างข้อมูล</button></div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<!-- panel default -->
</div>
<!-- container fulid -->
</form>
</div>
</div>
</div>
</div>
</div>
</div>
bamossza
พลังงานการช่วยเหลือ
( Level 3 )
( 16 )
ตอบกระทู้ ( 112 )
เขียนบทความ ( 28 )
หลังจากกดปุ่ม submit form (PHP)
HTML FORM(CODE)
ลองไปประยุทธ์อีกทีครับ แบบนี้ง่ายด้วย