<select>
   <option>--所有栏目--</option>
   <option>企业访谈</option>
   <option>企业访谈</option>
   <option>企业访谈</option>
   <option>企业访谈</option>
   <option>企业访谈</option>
</select>
<a href="addnews.php?action=addnew">添加新闻</a>
如果我使用默认的如:--所有栏目--  那么,我点击添加新闻的话,则提示“请选择要添加的栏目”,如果我选择企业访谈的话,则可以进入下一不

解决方案 »

  1.   

    你可以通过取option的value值来做判断,比如你可以把所有栏目的value值为空,判断如果value值为空就提示请选择要添加的栏目
      

  2.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <script>
    var $ = function(id){
    return document.getElementById(id);
    };
    var jump = function(){ 
    if($('myselect').selectedIndex == 0){
    alert("请选择企业栏目");
    }else{
    window.location.href  = 'addnews.php?action=addnew';
    }
    };
    </script>
    </HEAD><BODY>
    <select id="myselect">
      <option>--所有栏目--</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
    </select>
    <a href="javascript:jump()">添加新闻</a>
    </BODY>
    </HTML>
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title> New Document </title>
     </head> <body>
      <select id="s">
      <option>--所有栏目--</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
    </select>
    <a href="addnews.php?action=addnew" onclick="return sub();">添加新闻</a><script type="text/javascript">
    var sub=function(){
    var s=document.getElementById("s");
    if(0 == s.selectedIndex){
    alert("请选择栏目");
    return false;
    }
    return true;
    }
    </script>
     </body>
    </html>
      

  4.   

    这是我全部代码
     <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>
      

  5.   

    2 楼的如果把所有栏目放到最后面那不是还得查总共有几个option,这样不太好吧没有扩展性。
      

  6.   

    那就用这个判断
    if(s.options[s.selectedIndex].text == "--所有栏目--")
      

  7.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <script>
        var $ = function(id){
            return document.getElementById(id);
        };
        var jump = function(){ 
            if($('myselect').value== 0){
                alert("请选择企业栏目");
            }else{
                do what you want to do..........
            }
        };
    </script>
    </HEAD><BODY>
    <select id="myselect">
      <option value=0>--所有栏目--</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
    </select>我个人觉得还是这样好点。
      

  8.   

    楼主我建议你用value来判断,用汉字是不准确的,而且很多地方是不支持的<option value="0">--所有栏目--</option>
      <option value="1">企业访谈</option>
      <option value="1">企业访谈</option>
      <option value="1">企业访谈</option>
      <option value="1">企业访谈</option>
      <option value="1">企业访谈</option>你的上一贴我给你写过一个了
      

  9.   

    <script type="text/javascript">
    <!--
    window.onload = function(){
    var a = document.getElementById("addnews");
    a.onclick = function(){
    var sel = document.getElementById("select");
    if(sel.options[0].selected){
    alert("请选择要添加的栏目!");
    return false;
    }
    };
    }
    -->
    </script>
    </head>
    <body>
    <select id="select">
      <option>--所有栏目--</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
      <option>企业访谈</option>
    </select>
    <a id="addnews" href="addnews.php?action=addnew">添加新闻</a>
    </body>
      

  10.   

    我用了 不能用 这是我要判断的代码   
    <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>
      

  11.   

    修改一下 select 的id名称var jump = function(){ 
            if($('newtypeid').selectedIndex == 0){
                alert("请选择企业栏目");
            }else{
                window.location.href  = 'addnews.php?action=addnew';
            }
        };