รบกวนดูโค๊ดเช็คค่าจากselct/listให้หน่อยครับมันมองเป็นคาว่างตลอด
คือผมต้องการเช็คค่าของinput แล้วก็select ก่อนที่จะทำการsubmitอะครับ ค่าของinput เช็คได้ แต่ค่าของ select/list เช็คไม่ได้อะครับ ไมรู้เกี่ยวกับการที่ดึงข้อมูลมาจากsqlหรือป่าวอะครับ รบกวนหน่อยนะครับพรุ่งจะเอาไปสมัครงาน
function chkval(){
var line =parseInt(document.getElementById("hdline").value);
for(var i=0;i<line;i++){
if(document.getElementById("s"+line).value=="0"){
alert(line);
return false;
}
else{
return true;
}
}
}
<?php
include('connect.php');
$sql="select*from product where type=1";
$result=mysql_query($sql);
$result2=mysql_query($sql);
$result3=mysql_query($sql);
$result4=mysql_query($sql);
$result5=mysql_query($sql);
$rows=mysql_num_rows($result);
?>
<form name="frmmain" method="post" action="t1.php" enctype="multipart/form-data" onsubmit="return chkval()">
<table align="center" width="445" border="1" id="tbExp" class="table">
<tr>
<td colspan="3"><div align="center">แบบฟร์อมเบิกอุปกรณ์</div></td>
</tr>
<tr>
<td ><div align="center">ชื่อผู้เบิก<input name="name" type="text" id="user" /></div></td>
<td colspan="2"><div align="center">แผนก<input name="section" type="text" /></div></td>
</tr>
<tr>
<th colspan="3"><div align="center">รายการอุปกรณ์</div></th>
</tr>
<tr>
<td><div align="center">ลำดับ</div></td>
<td><div align="center">จำนวน</div></td>
<td><div align="center">อุปกรณ์</div></td>
</tr>
<tr id="st1">
<td><div align="center">1</div></td>
<td><div align="center"><input type="text" name="p[0]" id="p1" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[0]"><option value="0" id="s1" ></option>
<?
while($ar=mysql_fetch_array($result)){
$data=$ar['name'];
?>
<option value="<?=$data?>"><?=$data?></option>
<? }
?></select></div></td>
</tr>
<tr id="st2">
<td><div align="center">2</div></td>
<td><div align="center"><input type="text" name="p[1]" id="p2" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[1]"><option value="0" id="s2"></option>
<?
while($ar2=mysql_fetch_array($result2)){
$data2=$ar2['name'];
?>
<option value="<?=$data2?>"><?=$data2?></option>
<? }
?>
</select></div></td>
</tr>
<tr id="st3">
<td><div align="center">3</div></td>
<td><div align="center"><input type="text" name="p[2]" id="p3" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[2]"><option value="0" id="s3"></option>
<?
while($ar3=mysql_fetch_array($result3)){
$data3=$ar3['name'];
?>
<option value="<?=$data3?>"><?=$data3?></option>
<? }
?>
</select></div></td>
</tr>
<tr id="st4">
<td><div align="center">4</div></td>
<td><div align="center"><input type="text" name="p[3]" id="p4" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[3]"><option value="0" id="s4"></option>
<?
while($ar4=mysql_fetch_array($result4)){
$data4=$ar4['name'];
?>
<option value="<?=$data4?>"><?=$data4?></option>
<? }
?>
</select></div></td>
</tr>
<tr id="st5">
<td><div align="center">5</div></td>
<td><div align="center"><input type="text" name="p[4]" id="p5" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[4]"><option value="0" id="s5"></option>
<?
while($ar5=mysql_fetch_array($result5)){
$data5=$ar5['name'];
?>
<option value="<?=$data5?>"><?=$data5?></option>
<? }
?>
</select></div></td>
</tr>
<tr>
<td colspan="3"><div align="center"><textarea name="txtare" cols="60" rows="2"></textarea></div></td>
</tr>
<tr>
<td colspan="2"><div align="center"><input name="btnAdd" type="submit" value="ส่งใบเบิก" ></div></td>
<td align="right" width="80"><input name="btnAdd" type="button" id="btnAdd" value="เพิ่มรายการ" onClick="showrow();"></td>
</tr>
</table>
<input type="hidden" name="hdline" id="hdline" value="1">
</form>
function chkval(){
var line =parseInt(document.getElementById("hdline").value);
for(var i=0;i<line;i++){
if(document.getElementById("s"+line).value=="0"){
alert(line);
return false;
}
else{
return true;
}
}
}
<?php
include('connect.php');
$sql="select*from product where type=1";
$result=mysql_query($sql);
$result2=mysql_query($sql);
$result3=mysql_query($sql);
$result4=mysql_query($sql);
$result5=mysql_query($sql);
$rows=mysql_num_rows($result);
?>
<form name="frmmain" method="post" action="t1.php" enctype="multipart/form-data" onsubmit="return chkval()">
<table align="center" width="445" border="1" id="tbExp" class="table">
<tr>
<td colspan="3"><div align="center">แบบฟร์อมเบิกอุปกรณ์</div></td>
</tr>
<tr>
<td ><div align="center">ชื่อผู้เบิก<input name="name" type="text" id="user" /></div></td>
<td colspan="2"><div align="center">แผนก<input name="section" type="text" /></div></td>
</tr>
<tr>
<th colspan="3"><div align="center">รายการอุปกรณ์</div></th>
</tr>
<tr>
<td><div align="center">ลำดับ</div></td>
<td><div align="center">จำนวน</div></td>
<td><div align="center">อุปกรณ์</div></td>
</tr>
<tr id="st1">
<td><div align="center">1</div></td>
<td><div align="center"><input type="text" name="p[0]" id="p1" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[0]"><option value="0" id="s1" ></option>
<?
while($ar=mysql_fetch_array($result)){
$data=$ar['name'];
?>
<option value="<?=$data?>"><?=$data?></option>
<? }
?></select></div></td>
</tr>
<tr id="st2">
<td><div align="center">2</div></td>
<td><div align="center"><input type="text" name="p[1]" id="p2" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[1]"><option value="0" id="s2"></option>
<?
while($ar2=mysql_fetch_array($result2)){
$data2=$ar2['name'];
?>
<option value="<?=$data2?>"><?=$data2?></option>
<? }
?>
</select></div></td>
</tr>
<tr id="st3">
<td><div align="center">3</div></td>
<td><div align="center"><input type="text" name="p[2]" id="p3" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[2]"><option value="0" id="s3"></option>
<?
while($ar3=mysql_fetch_array($result3)){
$data3=$ar3['name'];
?>
<option value="<?=$data3?>"><?=$data3?></option>
<? }
?>
</select></div></td>
</tr>
<tr id="st4">
<td><div align="center">4</div></td>
<td><div align="center"><input type="text" name="p[3]" id="p4" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[3]"><option value="0" id="s4"></option>
<?
while($ar4=mysql_fetch_array($result4)){
$data4=$ar4['name'];
?>
<option value="<?=$data4?>"><?=$data4?></option>
<? }
?>
</select></div></td>
</tr>
<tr id="st5">
<td><div align="center">5</div></td>
<td><div align="center"><input type="text" name="p[4]" id="p5" onkeypress="check_number(event)"></div></td>
<td><div align="center"><select name="data[4]"><option value="0" id="s5"></option>
<?
while($ar5=mysql_fetch_array($result5)){
$data5=$ar5['name'];
?>
<option value="<?=$data5?>"><?=$data5?></option>
<? }
?>
</select></div></td>
</tr>
<tr>
<td colspan="3"><div align="center"><textarea name="txtare" cols="60" rows="2"></textarea></div></td>
</tr>
<tr>
<td colspan="2"><div align="center"><input name="btnAdd" type="submit" value="ส่งใบเบิก" ></div></td>
<td align="right" width="80"><input name="btnAdd" type="button" id="btnAdd" value="เพิ่มรายการ" onClick="showrow();"></td>
</tr>
</table>
<input type="hidden" name="hdline" id="hdline" value="1">
</form>
ถามเองตอบเอง ขอโทษด้วยครับ ตกม้าตายสะงั้น .ใส่idผิดที่
555+ เป็นเหมือนกัน