<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_form">
<tr>
<form name="addnews" action="addnews.php" method="GET">
<th width="90%" align="right">
<div align="right">
<select name="newtypeid" id="newtypeid">
<option value="0">--所有栏目--</option>
<?php
$sql = "select * from newtype";
$conn = mysql_connect("localhost","root","123456");$st = mysql_select_db("install",$conn);
mysql_query("set names gbk");
$rs = mysql_query($sql);;
while ($row = mysql_fetch_array($rs, MYSQL_BOTH))
{echo "<option value=".$row[typeid].">".$row["typetitle"]."</option>";}
mysql_free_result($rs);
mysql_close($conn);?>
</select>
</div></th>
<th width="10%" align="right"><input name="addnews" type="submit" value="添加新闻"></th>
</form>
</tr>
</table>
如果我使用默认的如:--所有栏目-- 那么,我点击添加新闻的话,则提示“请选择要添加的栏目”,如果我选择企业访谈的话,则可以进入下一步
<form name="addnews" action="addnews.php" method="GET" onSubmit='return check_selected();'>function check_selected(){
var val = document.getElementById('newtypeid').value;
if (val == '0'){
alert('请选择要添加的栏目');
return false;
}
}