表单没验证完就直接提交了!

xiexuanbin 2009-12-25 02:55:37
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>验证网址</title>
<style type="text/css">
<!--
.style1 {font-size: 13px}
.style2 {
font-size: 12px;
color: #FF0000;
}
.style3 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">
function checkURL(URL){
var str=URL;
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
</script>
<script language="javascript">
function checkform1(){
var www=form1.www.value;
if(www==""){
alert("请输入个人主页地址!");
document.form1.www.focus();
}else{
if(!checkURL(www)){
alert("您输入的个人主页地址不合法!");
document.form1.www.focus();
return;
}
}
form1.submit();
}
</script>

<body>
<table width="450" border="1" cellpadding="0" cellspacing="0" background="images/sss.JPG">

<form name="form1" method="post" action="eecdss.php"> <tr align="center">
<td height="24" colspan="2" class="style1">验证网址</td>
</tr>
<tr>
<td height="20" align="center" class="style1">个人空间:</td>
<td class="style3"><input name="www" type="text" id="www" size="20" maxlength="70">
<span class="style2"> * 请输入正确的个人空间地址</span></td>
</tr>
<tr>
<td height="24" align="center"> </td>
<td class="style3"><input type="button" name="Submit" value="提交" onClick="checkform1();">
<span class="style2"> (*为必填项目)</span> <input type="reset" name="Submit2" value="重置">

</td>
</tr>
</form>
</table>
</body>
</html>
...全文
138 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiexuanbin 2009-12-25
  • 打赏
  • 举报
回复
哎呀,把这问题弄复杂了,我说明白点吧,
<input name="uucs" type="text" id="uucs" size="20" maxlength="70">
这段表单是开始要提交到 action="eecdss.php"这里的,
然后我要给这个表单加个网址验证,就从网上找了这段代码?

</style>
</head>
<script language="javascript">
function checkURL(URL){
var str=URL;
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
</script>
<script language="javascript">
function checkform1(){
var www=form1.www.value;
if(www==""){
alert("请输入个人主页地址!");
document.form1.www.focus();
return false;
}else{
if(!checkURL(www)){
alert("您输入的个人主页地址不合法!");
document.form1.www.focus();
returnfalse;
}
}
form1.submit();
}
</script>
<input name="www" type="text" id="www" size="20" maxlength="70">
<input type="button" name="Submit" value="提交" onClick="returncheckform1();">
<span class="style2"> (*为必填项目) </span> <input type="reset" name="Submit2" value="重置">

然而开始表单里的name="uucs" id="uucs" 是不能动的,而我找的代码里的表单的是name="www" id="www"
我就想知道这个该怎么改,
谢谢各位了!
烟雨鹏城 2009-12-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lihui_shine 的回复:]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>验证网址 </title>
<style type="text/css">
<!--
.style1 {font-size: 13px}
.style2 {
font-size: 12px;
color: #FF0000;
}
.style3 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">
function checkURL(URL){
var str=URL;
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
  return true;
}else{
  return false;
}
}
</script>
<script language="javascript">
function checkform1(){
var www=form1.www.value;
if(www==""){
  alert("请输入个人主页地址!");
  document.form1.www.focus();
return false;
}else{
  if(!checkURL(www)){
    alert("您输入的个人主页地址不合法!");
    document.form1.www.focus();
    returnfalse;
  }
}
form1.submit();
}
</script>

<body>
<table width="450" border="1" cellpadding="0" cellspacing="0" background="images/sss.JPG">

<form name="form1" method="post" action="eecdss.php"> <tr align="center">
    <td height="24" colspan="2" class="style1">验证网址 </td>
    </tr>
<tr>
    <td height="20" align="center" class="style1">个人空间: </td>
    <td class="style3"> <input name="www" type="text" id="www" size="20" maxlength="70">
      <span class="style2"> * 请输入正确的个人空间地址 </span> </td>
</tr>
<tr>
    <td height="24" align="center"> </td>
    <td class="style3"> <input type="button" name="Submit" value="提交" onClick="returncheckform1();">
      <span class="style2">      (*为必填项目) </span>        <input type="reset" name="Submit2" value="重置">

      </td>
</tr>
</form>
</table>
</body>
</html>
[/Quote]支持
xiexuanbin 2009-12-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 lihui_shine 的回复:]
引用 9 楼 xiexuanbin 的回复:
<input name="www" type="text" id="www" size="20" maxlength="70">

name="www"  id="www" 里面的WWW我能换成其它的吗?要怎么换!

当然可以换了,比如换成url
<input name="url" type="text" id="url" size="20" maxlength="70">

另外别忘了,JS里面也要相应的修改

[/Quote]
我就是想问的是JS里面怎么修改,刚才试着改了一下,好像没用,不知道具体改哪些地方!
RYAN--333 2009-12-25
  • 打赏
  • 举报
回复
return false
xiexuanbin 2009-12-25
  • 打赏
  • 举报
回复
我就是想问的是JS里面怎么修改,刚才试着改了一下,好像没用,不知道具体改哪些地方!
浪尖赏花 2009-12-25
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xiexuanbin 的回复:]
<input name="www" type="text" id="www" size="20" maxlength="70">

name="www"  id="www" 里面的WWW我能换成其它的吗?要怎么换!
[/Quote]
当然可以换了,比如换成url
<input name="url" type="text" id="url" size="20" maxlength="70">

另外别忘了,JS里面也要相应的修改
xiexuanbin 2009-12-25
  • 打赏
  • 举报
回复
小弟不才,请大师们指点!
xiexuanbin 2009-12-25
  • 打赏
  • 举报
回复
<input name="www" type="text" id="www" size="20" maxlength="70">

name="www" id="www" 里面的WWW我能换成其它的吗?要怎么换!
浪尖赏花 2009-12-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xiexuanbin 的回复:]
大师请问改哪了!怎么回事啊!
[/Quote]
看1L红色部分
凤凰涅檠 2009-12-25
  • 打赏
  • 举报
回复
return false
phoeni_xin 2009-12-25
  • 打赏
  • 举报
回复

function checkform1(){
var www=form1.www.value;
if(www==""){
alert("请输入个人主页地址!");
document.form1.www.focus();
return false;
}else{
if(!checkURL(www)){
alert("您输入的个人主页地址不合法!");
document.form1.www.focus();
return false;
}
}
form1.submit();
return true;
}
xiexuanbin 2009-12-25
  • 打赏
  • 举报
回复
大师请问改哪了!怎么回事啊!
辉之不趣 2009-12-25
  • 打赏
  • 举报
回复
alert("请输入个人主页地址!");
document.form1.www.focus();

//加上这句
return;
zhulei2008 2009-12-25
  • 打赏
  • 举报
回复
楼上的还真快
zhulei2008 2009-12-25
  • 打赏
  • 举报
回复
表单没验证通过应该返回FALSE,这样就不会提交了

正确如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>验证网址 </title>
<style type="text/css">
<!--
.style1 {font-size: 13px}
.style2 {
font-size: 12px;
color: #FF0000;
}
.style3 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">
function checkURL(URL){
var str=URL;
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
</script>
<script language="javascript">
function checkform1(){
var www=form1.www.value;
if(www==""){
alert("请输入个人主页地址!");
document.form1.www.focus();
return false;
}else{
if(!checkURL(www)){
alert("您输入的个人主页地址不合法!");
document.form1.www.focus();
return false;
}
}
form1.submit();
return true;
}
</script>

<body>
<table width="450" border="1" cellpadding="0" cellspacing="0" background="images/sss.JPG">

<form name="form1" method="post" action="eecdss.php"> <tr align="center">
<td height="24" colspan="2" class="style1">验证网址 </td>
</tr>
<tr>
<td height="20" align="center" class="style1">个人空间: </td>
<td class="style3"> <input name="www" type="text" id="www" size="20" maxlength="70">
<span class="style2"> * 请输入正确的个人空间地址 </span> </td>
</tr>
<tr>
<td height="24" align="center"> </td>
<td class="style3"> <input type="button" name="Submit" value="提交" onClick="return checkform1();">
<span class="style2"> (*为必填项目) </span> <input type="reset" name="Submit2" value="重置">

</td>
</tr>
</form>
</table>
</body>
</html>
浪尖赏花 2009-12-25
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>验证网址 </title>
<style type="text/css">
<!--
.style1 {font-size: 13px}
.style2 {
font-size: 12px;
color: #FF0000;
}
.style3 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">
function checkURL(URL){
var str=URL;
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
</script>
<script language="javascript">
function checkform1(){
var www=form1.www.value;
if(www==""){
alert("请输入个人主页地址!");
document.form1.www.focus();
return false;
}else{
if(!checkURL(www)){
alert("您输入的个人主页地址不合法!");
document.form1.www.focus();
return false;
}
}
form1.submit();
}
</script>

<body>
<table width="450" border="1" cellpadding="0" cellspacing="0" background="images/sss.JPG">

<form name="form1" method="post" action="eecdss.php"> <tr align="center">
<td height="24" colspan="2" class="style1">验证网址 </td>
</tr>
<tr>
<td height="20" align="center" class="style1">个人空间: </td>
<td class="style3"> <input name="www" type="text" id="www" size="20" maxlength="70">
<span class="style2"> * 请输入正确的个人空间地址 </span> </td>
</tr>
<tr>
<td height="24" align="center"> </td>
<td class="style3"> <input type="button" name="Submit" value="提交" onClick="return checkform1();">
<span class="style2"> (*为必填项目) </span> <input type="reset" name="Submit2" value="重置">

</td>
</tr>
</form>
</table>
</body>
</html>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧