<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>添加新闻</title>
<script language="JavaScript">
function check_form(form1)
{
if (document.form1.content.value=="")
{
alert("请输入新闻内容!");
document.form1.content.focus();
return false;
}
if (document.form1.title.value=="")
{
alert("请留下新闻标题!");
document.form1.title.focus();
return false;
}
if (document.form1.editor.value=="")
{
alert("请输入编辑名字!");
document.form1.editor.focus();
return false;
}
if (document.form1.editor.value=="")
{
alert("请输入新闻来源!");
document.form1.from.focus();
return false;
}}
</script>
</head>

<body>
<form onsubmit="return check_form(this)" action="addnews.php" method="post" name="form1">
<table width="654" height="388" border="0">
  <tr>
    <td width="185">新闻标题:</td>
    <td width="442"><input type="text" name="title">
      <select name="newsTypeID" size="1">
        <option>news1</option>
        <option>news2</option>
        <option>news3</option>
      </select>  
      </tr>
  <tr>
    <td>图片名称:</td>
    <td>
      <input type="text" name="picname"></td>
  </tr>
  <tr>
    <td>编辑:</td>
    <td>
      <input type="text" name="editor">
  </td>
  </tr>
  <tr>
    <td>来源:</td>
    <td>
      <input type="text" name="from">
    </td>
  </tr>
  <tr>
    <td>时间:</td>
    <td>
      <input type="text" name="time">
    </td>
  </tr>
  <tr>
    <td height="94">内容:</td>
    <td>
      <textarea name="content"></textarea>
      <input type="Submit" name="Submit" value="提交">
    </td>
  </tr>
</table>
</form>
</body>
</html>什么都不填的时候提交,弹出对话框(正常),关掉对话框提示下载addnews.php文件.
怎么样使其什么不填的时候不提交呢?不提示下载addnews.php文件.

解决方案 »

  1.   

    不提示下载addnews.php文件..php一般来说是服务器端的文件,提示下载代码你还没有配置好
      

  2.   

    <script language="JavaScript">
    function check_form()
    {
    if (document.form1.content.value=="")
    {
    alert("请输入新闻内容!");
    document.form1.text.focus();
    }
    else if (document.form1.title.value=="")
    {
    alert("请留下新闻标题!");
    document.form1.title.focus();
    }
    else if (document.form1.editor.value=="")
    {
    alert("请输入编辑名字!");
    document.form1.editor.focus();
    }
    else if (document.form1.editor.value=="")
    {
    alert("请输入新闻来源!");
    document.form1.from.focus();
    }
                      else
                      {
                               document.form1.submit();
                      }}
    </script>
    <input type="button" name="Submit" value="提交" onclick="check_form();">
      

  3.   

    if (document.form1.content.value=="")
    {
    alert("请输入新闻内容!");
    document.form1.text.focus();
    return false;
    }你这里有错误,document.form1.text.focus();因为document.form1.text在页面里找不到。
    document.form1.content.focus()