×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

I need your help on 2 Sample codes Thanks a lot. I am a begainer. Don't laugh at me.

本文发表在 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
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / I need your help on 2 Sample codes Thanks a lot. I am a begainer. Don't laugh at me.
    本文发表在 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
    • 1.应该是 == "none",而不是 = "none" 2.不用第一个html文件,只使用asp那个,post给自己
      • Thanks, the first problem has been fixed. I am working on the second problem. Tell me more detail if you can. Thanks
    • Why don't you just place a simple javascript in the first page to check??? As like you did in the first example.
      • The second sample is simplified pretty much from original intendency.The problem is to how to retrieve and redisplay the entered form data. It's not to check if the filed is empty or not.Thank you anyway
        • Okay. Most likely in any website, you have to keep the username information for further use. So use a session vbl to store the username. And then in the first page, you will have back end VBScript or JScript
          to determine whether the session vbl has value. If it does, set the default value to the session vbl, esle, leave the default value empty.

          Though it seems like you need to put an if statement, but the problem can be simplified to 1 line by using syntax such as
          Session.username=="user"?Response.write(Session.username):Response.write("")

          in JScript.
    • 第二个,用login.asp + valid.asp,valid不通过,就把两个值再post回去显示即可。
      • Too abstract for me.Could u show me some sample codes? I'll appreciate that.