JS提交表单问题 20
思路:1.php--用户输入信息后通过js简单验证,提交给2.php.代码如下:1.php:<scriptlanguage="javascript"src="2.php"...
思路:1.php--用户输入信息后通过js简单验证,提交给2.php.代码如下:
1.php:
<script language="javascript" src="2.php">
<!--
function check()
{
var name=document.form1.name.value;
if(name=='')
{
alert('用户名不能为空!');
return false;
}
return true;
}
-->
</script>
</head>
<body>
<form name="form1" action="2.php" method="post" onsubmit="return check()">
<input type="text" name="name">
<input type="submit" name="submit" value="提交">
</form>
2.php
<?php
$name=$_POST["name"];
echo $name;
?>
问题出来,js的验证不起作用了,如果就1.php本页来说,即是:
<?php
$name=$_POST["name"];
echo $name;
?>
<script language="javascript" >
<!--
function check()
{
var name=document.form1.name.value;
if(name=='')
{
alert('用户名不能为空!');
return false;
}
return true;
}
-->
</script>
</head>
<body>
<form name="form1" action="1.php" method="post" onsubmit="return check()">
<input type="text" name="name">
<input type="submit" name="submit" value="提交">
</form>
那么js的验证就有效! 展开
1.php:
<script language="javascript" src="2.php">
<!--
function check()
{
var name=document.form1.name.value;
if(name=='')
{
alert('用户名不能为空!');
return false;
}
return true;
}
-->
</script>
</head>
<body>
<form name="form1" action="2.php" method="post" onsubmit="return check()">
<input type="text" name="name">
<input type="submit" name="submit" value="提交">
</form>
2.php
<?php
$name=$_POST["name"];
echo $name;
?>
问题出来,js的验证不起作用了,如果就1.php本页来说,即是:
<?php
$name=$_POST["name"];
echo $name;
?>
<script language="javascript" >
<!--
function check()
{
var name=document.form1.name.value;
if(name=='')
{
alert('用户名不能为空!');
return false;
}
return true;
}
-->
</script>
</head>
<body>
<form name="form1" action="1.php" method="post" onsubmit="return check()">
<input type="text" name="name">
<input type="submit" name="submit" value="提交">
</form>
那么js的验证就有效! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询