⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 password field validation - help - javascript.htm

📁 password field validation - help - JavaScript.htm
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            type="submit" value="Submit Application"<BR>onSubmit="if(this.value 
            == 'Continue') 
            this.form.submit();"&gt;<BR>&lt;/body&gt;<BR>&lt;/html&gt;<BR><BR>Thanks 
            in advance for all replies. Mike<BR></DIV><!-- / message -->
            <DIV style="FONT-SIZE: 9pt; MARGIN: 20px 0px 10px"><!-- controls -->
            <DIV 
            style="text-decorations: underline"></DIV><!-- / controls --></DIV><!-- message, attachments, sig --></DIV></DIV><!-- / post #311313 --><!-- post #311313 -->
            <DIV 
            style="BORDER-TOP: #999 1px solid; MARGIN-BOTTOM: 15px; MARGIN-TOP: 5px; PADDING-BOTTOM: 50px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 20px"><!-- user info -->
            <DIV><!-- avatar float left --><A 
            href="http://bytes.com/forum/member.php?u=" rel=nofollow><IMG 
            alt="Michael Winter's Avatar" border=0 class=avtr 
            src="password field validation - help - JavaScript_files/noavatar.gif"></A> 

            <DIV id=postmenu_311313>
            <DIV style="FONT-SIZE: 9pt">Michael Winter <SPAN 
            style="FONT-WEIGHT: normal"><A 
            href="http://bytes.com/forum/post311313-5.html" rel=nofollow 
            style="FONT-SIZE: 9pt" target=new>July 20th, 2005 01:28 PM</A> 
            </SPAN></DIV>
            <DIV style="COLOR: #666; FONT-SIZE: 9pt">Guest - n/a Posts </DIV>
            <DIV style="COLOR: #666; FONT-SIZE: 9pt">#5: Re: password field 
            validation - help</DIV></DIV></DIV><!-- / user info --><BR>
            <DIV style="FONT-SIZE: 10pt; MARGIN-LEFT: 64px"><!-- message, attachments, sig --><!-- message -->
            <DIV style="PADDING-TOP: 10px">Mike wrote on 30 Nov 
            2003:<BR>[color=blue]<BR>&gt; &lt;html&gt;<BR>&gt; 
            &lt;head&gt;<BR>&gt; &lt;title&gt;Test Page 01&lt;/title&gt;<BR>&gt; 
            &lt;META http-equiv="Content-Script-Type"<BR>&gt; 
            content="text/javascript"&gt; &lt;script 
            type="text/javascript"&gt;<BR>&gt; function checkPw(element) 
            {<BR>&gt; pw1 = 
            document.forms['FormName'].elements['pw1'].value;<BR>&gt;<BR>&gt; 
            pw2 = element.value;<BR>&gt; if (pw1 != pw2) {<BR>&gt; window.alert 
            ("Passwords do not match. Please<BR>&gt; re-enter."); 
            document.FormName.pw1.value="";<BR>&gt; window.alert ("Please enter 
            a password.");<BR>&gt; document.FormName.pw2.value="";<BR>&gt; 
            window.alert ("Please re-enter your password.");<BR>&gt; 
            document.FormName.pw1.focus();<BR>&gt; }<BR>&gt; // --&gt;<BR>&gt; 
            &lt;/script&gt;<BR>&gt; &lt;/head&gt;<BR>&gt; &lt;body&gt;<BR>&gt; 
            &lt;form action="http://www.photoshelf.net/cgi-bin/mailto"<BR>&gt; 
            onsubmit="return FrontPage_Form1_Validator(this)" 
            method="post"<BR>&gt; name="FormName"&gt;<BR>&gt; &lt;input 
            type="text" name="UserName" size="20" maxlength="60"&gt;<BR>&gt; 
            &lt;input type="password" name="pw1" size="20" 
            maxlength="60"&gt;<BR>&gt; &lt;input type="password" name="pw2" 
            size="20" maxlength="60"<BR>&gt; "this.value"&gt;&lt;br&gt;<BR>&gt; 
            &lt;input type="submit" value="Submit Application"<BR>&gt; 
            onSubmit="if(this.value == 'Continue') 
            this.form.submit();"&gt;<BR>&gt; &lt;/body&gt;<BR>&gt; 
            &lt;/html&gt;[/color]<BR><BR>If this is exactly what you are 
            testing, it's because the function<BR>(used in the form onsubmit 
            event) FrontPage_Form1_Validator() doesn't<BR>exist.<BR><BR>You 
            should remove the closing SGML comment (// --&gt;) at the end of 
            the<BR>script block.<BR><BR>Finally, you should remove the onsubmit 
            event on the submit button.<BR>INPUT elements (of any type) don't 
            have such an event, so it means<BR>and does nothing.<BR><BR>Here's 
            some advice to help you do the other things you asked about 
            in<BR>your original post:<BR><BR>You've already got the maximum 
            lengths restricted in your HTML. To<BR>set a minimum length, use 
            [control reference].value.length. 
            For<BR>example:<BR><BR>document.forms['FormName'].elements['pw1'].value.length<BR><BR>To 
            disable the submit button, place the following at the end of 
            the<BR>validation script so it will be executed when the form 
            validates<BR>correctly:<BR><BR>document.forms['FormName'].elements['submitButtonName'].disabled 
            =<BR>true;<BR><BR>If you make all these changes and add a proper 
            onsubmit event handler<BR>for the form, your document above would 
            look something like:<BR><BR>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD 
            HTML 
            4.01//EN"<BR>"http://www.w3.org/TR/html4/strict.dtd"&gt;<BR><BR>&lt;HTML&gt;<BR>&lt;HEAD&gt;<BR>&lt;META 
            http-equiv="Content-Script-Type" 
            content="text/javascript"&gt;<BR><BR>&lt;TITLE&gt;Test Page 
            01&lt;/TITLE&gt;<BR><BR>&lt;SCRIPT 
            type="text/javascript"&gt;<BR>function checkPw(form) {<BR>var pw1 = 
            form.elements['pw1'];<BR>var pw2 = form.elements['pw2'];<BR>var 
            minPasswordLength = 6;<BR><BR>// Check password length<BR>if 
            ((minPasswordLength &gt; pw1.value.length)<BR>|| (minPasswordLength 
            &gt; pw2.value.length)) {<BR>window.alert(<BR>'Passwords must be at 
            least ' + minPasswordLength<BR>+ ' characters 
            long.');<BR>pw1.focus();<BR>return false;<BR>}<BR><BR>// Check 
            password match<BR>if (pw1.value != pw2.value) 
            {<BR>window.alert(<BR>'The passwords do not match. Please 
            re-enter.');<BR>pw1.value = '';<BR>pw2.value = 
            '';<BR>pw1.focus();<BR>return false;<BR>}<BR><BR>// By now, the 
            passwords have been validated. The form can be<BR>// submitted, and 
            the submit button (I've named it 'apply'<BR>// for this example) can 
            be disabled.<BR>form.elements['apply'].disabled = true;<BR>return 
            true;<BR>}<BR>&lt;/SCRIPT&gt;<BR>&lt;/HEAD&gt;<BR><BR>&lt;BODY&gt;<BR>&lt;FORM 
            name="FormName" 
            method="post"<BR>action="http://www.photoshelf.net/cgi-bin/mailto"<BR>onsubmit="return 
            checkPw(this)"&gt;<BR>&lt;INPUT type="text" name="UserName" 
            size="20" maxlength="60"&gt;<BR>&lt;INPUT type="password" name="pw1" 
            size="20" maxlength="60"&gt;<BR>&lt;INPUT type="password" name="pw2" 
            size="20" maxlength="60"&gt;<BR>&lt;INPUT type="submit" name="apply" 
            value="Submit 
            Application"&gt;<BR>&lt;/BODY&gt;<BR>&lt;/HTML&gt;<BR><BR>Hope this 
            helps,<BR>Mike<BR><BR>Sorry, I didn't mean to write this for you, 
            but there were quite a<BR>few mistakes creeping in that would take 
            too much explanation to fix.<BR>I think I was giving you too much 
            new information without explaining<BR>it properly. My 
            fault.<BR><BR>--<BR>Michael Winter<BR><A 
            href="http://bytes.com/forum/register.php" rel=nofollow>Join 
            Bytes!</A>lid (remove ".invalid" to reply)<BR></DIV><!-- / message -->
            <DIV style="FONT-SIZE: 9pt; MARGIN: 20px 0px 10px"><!-- controls -->
            <DIV 
            style="text-decorations: underline"></DIV><!-- / controls --></DIV><!-- message, attachments, sig --></DIV></DIV><!-- / post #311492 --><!-- post #311492 -->
            <DIV 
            style="BORDER-TOP: #999 1px solid; MARGIN-BOTTOM: 15px; MARGIN-TOP: 5px; PADDING-BOTTOM: 50px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 20px"><!-- user info -->
            <DIV><!-- avatar float left --><A 
            href="http://bytes.com/forum/member.php?u=" rel=nofollow><IMG 
            alt="Mike's Avatar" border=0 class=avtr 
            src="password field validation - help - JavaScript_files/noavatar.gif"></A> 

            <DIV id=postmenu_311492>
            <DIV style="FONT-SIZE: 9pt">Mike <SPAN 
            style="FONT-WEIGHT: normal"><A 
            href="http://bytes.com/forum/post311492-6.html" rel=nofollow 
            style="FONT-SIZE: 9pt" target=new>July 20th, 2005 01:30 PM</A> 
            </SPAN></DIV>
            <DIV style="COLOR: #666; FONT-SIZE: 9pt">Guest - n/a Posts </DIV>
            <DIV style="COLOR: #666; FONT-SIZE: 9pt">#6: Re: password field 
            validation - help</DIV></DIV></DIV><!-- / user info --><BR>
            <DIV style="FONT-SIZE: 10pt; MARGIN-LEFT: 64px"><!-- message, attachments, sig --><!-- message -->
            <DIV style="PADDING-TOP: 10px">Michael Winter 
            &lt;M.Winter@blueyonder.co.uk.invalid&gt; wrote in message 
            news:&lt;Xns944496C0A542DMWinterBlueyonder@193.38.113.46&gt;...[color=blue]<BR>&gt; 
            Mike wrote on 30 Nov 2003:<BR>&gt;[color=green]<BR>&gt; &gt; 
            &lt;html&gt;<BR>&gt; &gt; &lt;head&gt;<BR>&gt; &gt; 
            &lt;title&gt;Test Page 01&lt;/title&gt;<BR>&gt; &gt; &lt;META 
            http-equiv="Content-Script-Type"<BR>&gt; &gt; 
            content="text/javascript"&gt; &lt;script 
            type="text/javascript"&gt;<BR>&gt; &gt; function checkPw(element) 
            {<BR>&gt; &gt; pw1 = 
            document.forms['FormName'].elements['pw1'].value;<BR>&gt; 
            &gt;<BR>&gt; &gt; pw2 = element.value;<BR>&gt; &gt; if (pw1 != pw2) 
            {<BR>&gt; &gt; window.alert ("Passwords do not match. Please<BR>&gt; 
            &gt; re-enter."); document.FormName.pw1.value="";<BR>&gt; &gt; 
            window.alert ("Please enter a password.");<BR>&gt; &gt; 
            document.FormName.pw2.value="";<BR>&gt; &gt; window.alert ("Please 
            re-enter your password.");<BR>&gt; &gt; 
            document.FormName.pw1.focus();<BR>&gt; &gt; }<BR>&gt; &gt; // 
            --&gt;<BR>&gt; &gt; &lt;/script&gt;<BR>&gt; &gt; 
            &lt;/head&gt;<BR>&gt; &gt; &lt;body&gt;<BR>&gt; &gt; &lt;form 
            action="http://www.photoshelf.net/cgi-bin/mailto"<BR>&gt; &gt; 
            onsubmit="return FrontPage_Form1_Validator(this)" 
            method="post"<BR>&gt; &gt; name="FormName"&gt;<BR>&gt; &gt; 
            &lt;input type="text" name="UserName" size="20" 
            maxlength="60"&gt;<BR>&gt; &gt; &lt;input type="password" name="pw1" 
            size="20" maxlength="60"&gt;<BR>&gt; &gt; &lt;input type="password" 
            name="pw2" size="20" maxlength="60"<BR>&gt; &gt; 
            "this.value"&gt;&lt;br&gt;<BR>&gt; &gt; &lt;input type="submit" 
            value="Submit Application"<BR>&gt; &gt; onSubmit="if(this.value == 
            'Continue') this.form.submit();"&gt;<BR>&gt; &gt; 
            &lt;/body&gt;<BR>&gt; &gt; &lt;/html&gt;[/color]<BR>&gt;<BR>&gt; If 
            this is exactly what you are testing, it's because the 
            function<BR>&gt; (used in the form onsubmit event) 
            FrontPage_Form1_Validator() doesn't<BR>&gt; exist.<BR>&gt;<BR>&gt; 
            You should remove the closing SGML comment (// --&gt;) at the end of 
            the<BR>&gt; script block.<BR>&gt;<BR>&gt; Finally, you should remove 
            the onsubmit event on the submit button.<BR>&gt; INPUT elements (of 
            any type) don't have such an event, so it means<BR>&gt; and does 
            nothing.<BR>&gt;<BR>&gt; Here's some advice to help you do the other 
            things you asked about in<BR>&gt; your original 
            post:<BR>&gt;<BR>&gt; You've already got the maximum lengths 
            restricted in your HTML. To<BR>&gt; set a minimum length, use 
            [control reference].value.length. For<BR>&gt; 
            example:<BR>&gt;<BR>&gt; 
            document.forms['FormName'].elements['pw1'].value.length<BR>&gt;<BR>&gt; 
            To disable the submit button, place the following at the end of 
            the<BR>&gt; validation script so it will be executed when the form 
            validates<BR>&gt; correctly:<BR>&gt;<BR>&gt; 
            document.forms['FormName'].elements['submitButtonName'].disabled 
            =<BR>&gt; true;<BR>&gt;<BR>&gt; If you make all these changes and 
            add a proper onsubmit event handler<BR>&gt; for the form, your 
            document above would look something like:<BR>&gt;<BR>&gt; 
            &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"<BR>&gt; 
            "http://www.w3.org/TR/html4/strict.dtd"&gt;<BR>&gt;<BR>&gt; 
            &lt;HTML&gt;<BR>&gt; &lt;HEAD&gt;<BR>&gt; &lt;META 
            http-equiv="Content-Script-Type" 
            content="text/javascript"&gt;<BR>&gt;<BR>&gt; &lt;TITLE&gt;Test Page 
            01&lt;/TITLE&gt;<BR>&gt;<BR>&gt; &lt;SCRIPT 
            type="text/javascript"&gt;<BR>&gt; function checkPw(form) {<BR>&gt; 
            var pw1 = form.elements['pw1'];<BR>&gt; var pw2 = 
            form.elements['pw2'];<BR>&gt; var minPasswordLength = 
            6;<BR>&gt;<BR>&gt; // Check password length<BR>&gt; if 
            ((minPasswordLength &gt; pw1.value.length)<BR>&gt; || 
            (minPasswordLength &gt; pw2.value.length)) {<BR>&gt; 
            window.alert(<BR>&gt; 'Passwords must be at least ' + 
            minPasswordLength<BR>&gt; + ' characters long.');<BR>&gt; 
            pw1.focus();<BR>&gt; return false;<BR>&gt; }<BR>&gt;<BR>&gt; // 
            Check password match<BR>&gt; if (pw1.value != pw2.value) {<BR>&gt; 
            window.alert(<BR>&gt; 'The passwords do not match. Please 
            re-enter.');<BR>&gt; pw1.value = '';<BR>&gt; pw2.value = '';<BR>&gt; 
            pw1.focus();<BR>&gt; return false;<BR>&gt; }<BR>&gt;<BR>&gt; // By 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -