本文发表在 rolia.net 枫下论坛In first sample, I want to make sure person to choose a country. But now no matter he choose a country or not, the alert "choose your country please"aways pops out. So what's wrong with my code?
------------------------------------
<html>
<head>
<title>New Page 1</title>
<script type="text/javascript">
function checkfields()
{
f1=document.register.newusername.value.length
f2=document.register.country.selectedIndex
if (f1<1)
{ alert ("Enter username please")
return false
}
if (document.register.country.options[f2].value="none")
{ alert ("Choose your country please")
return false
}
}
</script>
</head>
<body>
<form name="register" method="POST" onSubmit="return checkfields()">
Username<input name="newusername" size="20" ><br>
Country<select name="country" class=select>
<option value="none">Select a country
<option>Abu Dhabi
<option>Afghanistan <br>
<input type="submit" value="Submit" name="B1">
</body>
</html>
2. In second sample, if visitor doesn't enter password in Tobevalidated form,next page (validate02.asp) will remind him,and when he click return, I hope the input in username field will still be there. But I don't know how to do it. Now when I click return, all data lose.Actually I just simplified the comparison between the input password and the password in database here.So don't tell me use " if password="" staff like that.The problem here is how to redisplay entered data.Thanks A lot.
Tobevalidated form
----------------------------------------------------------------------
<html>
<head>
<title>New Page 2</title>
</head>
<body>
<form name="myform" action="http://localhost/myweb098/validate02.asp">
Username <input type="text" name="username"><br>
Password <input type="password" name="password"><br>
<input type="submit">
</form>
</body>
</html>
-------------------------validate02.asp
<%
sub errorform(theerror)
%>
<html>
<head>
<title>New Page 2</title>
</head>
<body>
<%=theerror%>
<form method="post" action="C:\WINDOWS\Desktop\tobevalidated.htm">
<% FOR EACH item IN Request.Form %>
<input name="<%=item%>" type="hidden" value="<%=Server.HTMLEncode(Request.Form(item))%>">
<%next%>
<p><input type="submit" value="return">
</form>
<%
Response.End
end sub
'retrieve form fileds
username=TRIM(Request.form("username"))
password=TRIM(Request.form("password"))
%>
<%' validate input
if password=""then
errorform "You didn't enter password"
end if
%>
</body>
</html>更多精彩文章及讨论,请光临枫下论坛 rolia.net
------------------------------------
<html>
<head>
<title>New Page 1</title>
<script type="text/javascript">
function checkfields()
{
f1=document.register.newusername.value.length
f2=document.register.country.selectedIndex
if (f1<1)
{ alert ("Enter username please")
return false
}
if (document.register.country.options[f2].value="none")
{ alert ("Choose your country please")
return false
}
}
</script>
</head>
<body>
<form name="register" method="POST" onSubmit="return checkfields()">
Username<input name="newusername" size="20" ><br>
Country<select name="country" class=select>
<option value="none">Select a country
<option>Abu Dhabi
<option>Afghanistan <br>
<input type="submit" value="Submit" name="B1">
</body>
</html>
2. In second sample, if visitor doesn't enter password in Tobevalidated form,next page (validate02.asp) will remind him,and when he click return, I hope the input in username field will still be there. But I don't know how to do it. Now when I click return, all data lose.Actually I just simplified the comparison between the input password and the password in database here.So don't tell me use " if password="" staff like that.The problem here is how to redisplay entered data.Thanks A lot.
Tobevalidated form
----------------------------------------------------------------------
<html>
<head>
<title>New Page 2</title>
</head>
<body>
<form name="myform" action="http://localhost/myweb098/validate02.asp">
Username <input type="text" name="username"><br>
Password <input type="password" name="password"><br>
<input type="submit">
</form>
</body>
</html>
-------------------------validate02.asp
<%
sub errorform(theerror)
%>
<html>
<head>
<title>New Page 2</title>
</head>
<body>
<%=theerror%>
<form method="post" action="C:\WINDOWS\Desktop\tobevalidated.htm">
<% FOR EACH item IN Request.Form %>
<input name="<%=item%>" type="hidden" value="<%=Server.HTMLEncode(Request.Form(item))%>">
<%next%>
<p><input type="submit" value="return">
</form>
<%
Response.End
end sub
'retrieve form fileds
username=TRIM(Request.form("username"))
password=TRIM(Request.form("password"))
%>
<%' validate input
if password=""then
errorform "You didn't enter password"
end if
%>
</body>
</html>更多精彩文章及讨论,请光临枫下论坛 rolia.net