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

📄 password field validation - help - javascript.htm

📁 password field validation - help - JavaScript.htm
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            re-enter.");[/color]<BR><BR>You should qualify that using window. 
            That is, window.alert(...). The<BR>collections comment above applies 
            to these, too:<BR>[color=blue]<BR>&gt; 
            document.FormName.pw1.value="";<BR>&gt; 
            document.FormName.pw2.value="";<BR>&gt; 
            document.FormName.pw1.focus();<BR>&gt; return 
            false;[/color]<BR><BR>Returning false should not be necessary here 
            (and may not do<BR>anything, anyway). The focus() call should keep 
            the box in focus.<BR>[color=blue]<BR>&gt; }[/color]<BR><BR>Not that 
            it matters here, due to what I just wrote, but in future, I<BR>would 
            suggest that if you return a value for one code path, every<BR>code 
            path should return a value.<BR>[color=blue]<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;[/color]<BR><BR>You're 
            using intrinsic events, but you didn't (in this sample) set<BR>the 
            default scripting language. This is invalid HTML. Place 
            the<BR>following META element in the document HEAD:<BR><BR>&lt;META 
            http-equiv="Content-Script-Type" 
            content="text/javascript"&gt;<BR>[color=blue]<BR>&gt; &lt;input 
            type="hidden" name="THANKURL"<BR>&gt; 
            value="http://www.somepage.org/ok.htm"&gt;<BR>&gt; &lt;input 
            type="hidden" name="RECIPIENT"<BR>&gt; 
            value="someone@somepage.com"&gt;[/color]<BR><BR>This is a /huge/ 
            security risk. Never use a mail form that requires a<BR>full "To:" 
            address - it's an easy target for spam (both for receiving<BR>it, 
            and sending it).<BR>[color=blue]<BR>&gt; &lt;input type="text" 
            name="UserName"<BR>&gt; size="20" maxlength="60"&gt; &lt;input 
            type="password" name="pw1"<BR>&gt; size="20" maxlength="60"&gt; 
            &lt;input type="password" name="pw2"<BR>&gt; size="20" 
            maxlength="60" 
            onBlur="checkPw(this)"&gt;&lt;br&gt;[/color]<BR><BR>The check should 
            really be done upon submission. If I choose to do<BR>something else 
            before completing a matching password (including<BR>changing my 
            original password), I'll be trapped in this input field.<BR>There's 
            also no need to pass the entire object: just pass the value<BR>using 
            this.value.<BR>[color=blue]<BR>&gt; &lt;input type="submit" 
            value="Submit Application"<BR>&gt; onClick="if(this.value == 
            'Continue') this.form.submit();"&gt;[/color]<BR><BR>From what you've 
            shown, that onclick event doesn't seem to do<BR>anything. It would 
            have been helpful if you had shown the function<BR>called by the 
            form's onsubmit event.<BR><BR>Apply the suggestions I've made so 
            far. If it's not enough, say so,<BR>and include the function called 
            by the onsubmit event and explain<BR>your restrictions in more 
            detail, and I'll try again.<BR><BR>Good 
            luck,<BR>Mike<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 #311243 --><!-- post #311243 -->
            <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_311243>
            <DIV style="FONT-SIZE: 9pt">Mike <SPAN 
            style="FONT-WEIGHT: normal"><A 
            href="http://bytes.com/forum/post311243-4.html" rel=nofollow 
            style="FONT-SIZE: 9pt" target=new>July 20th, 2005 01:27 PM</A> 
            </SPAN></DIV>
            <DIV style="COLOR: #666; FONT-SIZE: 9pt">Guest - n/a Posts </DIV>
            <DIV style="COLOR: #666; FONT-SIZE: 9pt">#4: 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;Xns9442AC31A84B5MWinterBlueyonder@193.38.113.46&gt;...[color=blue]<BR>&gt; 
            Mike wrote on 29 Nov 2003:<BR>&gt;[color=green]<BR>&gt; &gt; I've 
            been trying for the past week to put a simple code<BR>&gt; &gt; 
            together. I have done a LOT of searching, found scripts 
            showing<BR>&gt; &gt; the functions I would like to use, however when 
            I mix them it<BR>&gt; &gt; all goes wrong, somehow I always end up 
            with error messages and<BR>&gt; &gt; functions not working right. 
            Can someone please help me?<BR>&gt; &gt;<BR>&gt; &gt; I have a form, 
            inside is 1 Text Field and 2 Password Fields.<BR>&gt; &gt; What I'm 
            looking to do is:<BR>&gt; &gt; - Make sure password fields are 
            equal<BR>&gt; &gt; - Set Minimum/Maximum amount of characters in 
            each field<BR>&gt; &gt; - Disable submit button after clicking 
            submit[/color]<BR>&gt;<BR>&gt; That's a dangerous thing to do. If a 
            user clicks the 'Back' button,<BR>&gt; the submit button will still 
            be disabled (control states are usually<BR>&gt; saved) and the user 
            has to go back again, then forward to restore the<BR>&gt; initial 
            settings. It might not matter in this case, though (due to<BR>&gt; 
            the nature of the form).<BR>&gt;[color=green]<BR>&gt; &gt; I plan to 
            add more text fields in the future. Will I be able to?<BR>&gt; &gt; 
            I know how to add it in the form, but how do I change the<BR>&gt; 
            &gt; script?[/color]<BR>&gt;<BR>&gt; The text fields have nothing to 
            do with the validation of the<BR>&gt; password fields so you could 
            add anything you like and it will have<BR>&gt; no effect, or does 
            the number of characters condition you state above<BR>&gt; apply to 
            literally /every/ field? If so, and the limits are the same<BR>&gt; 
            for all fields, or all types of field (60 for password types, 30 
            for<BR>&gt; text, 1000 for textarea, etc), there is no problem. If 
            not (the<BR>&gt; limits vary from field to field) it could become a 
            little more<BR>&gt; complicated. You'll have to explain more about 
            the changes you might<BR>&gt; make.<BR>&gt;[color=green]<BR>&gt; 
            &gt; &lt;script language="JavaScript"&gt;[/color]<BR>&gt;<BR>&gt; 
            There is no need to use the language attribute (it is, in 
            fact,<BR>&gt; discouraged), but you /must/ use type 
            (type="text/javascript")<BR>&gt;[color=green]<BR>&gt; &gt; 
            &lt;!--[/color]<BR>&gt;<BR>&gt; You don't need to use SGML comments 
            in SCRIPT blocks.<BR>&gt;[color=green]<BR>&gt; &gt; function 
            checkPw(element) {<BR>&gt; &gt; pw1 = 
            document.FormName.pw1.value;[/color]<BR>&gt;<BR>&gt; You should use 
            the forms and elements collections, like so:<BR>&gt;<BR>&gt; pw1 = 
            document.forms['FormName'].elements['pw1'].value;<BR>&gt;<BR>&gt; It 
            aids in compatibility. You should also use the var keyword 
            to<BR>&gt; declare the variable, otherwise it ends up becoming a 
            global.<BR>&gt;[color=green]<BR>&gt; &gt; pw2 = 
            element.value;<BR>&gt; &gt; if (pw1 != pw2) {<BR>&gt; &gt; alert 
            ("Passwords do not match. Please 
            re-enter.");[/color]<BR>&gt;<BR>&gt; You should qualify that using 
            window. That is, window.alert(...). The<BR>&gt; collections comment 
            above applies to these, too:<BR>&gt;[color=green]<BR>&gt; &gt; 
            document.FormName.pw1.value="";<BR>&gt; &gt; 
            document.FormName.pw2.value="";<BR>&gt; &gt; 
            document.FormName.pw1.focus();<BR>&gt; &gt; return 
            false;[/color]<BR>&gt;<BR>&gt; Returning false should not be 
            necessary here (and may not do<BR>&gt; anything, anyway). The 
            focus() call should keep the box in 
            focus.<BR>&gt;[color=green]<BR>&gt; &gt; }[/color]<BR>&gt;<BR>&gt; 
            Not that it matters here, due to what I just wrote, but in future, 
            I<BR>&gt; would suggest that if you return a value for one code 
            path, every<BR>&gt; code path should return a 
            value.<BR>&gt;[color=green]<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;[/color]<BR>&gt;<BR>&gt; You're using intrinsic 
            events, but you didn't (in this sample) set<BR>&gt; the default 
            scripting language. This is invalid HTML. Place the<BR>&gt; 
            following META element in the document HEAD:<BR>&gt;<BR>&gt; 
            &lt;META http-equiv="Content-Script-Type" 
            content="text/javascript"&gt;<BR>&gt;[color=green]<BR>&gt; &gt; 
            &lt;input type="hidden" name="THANKURL"<BR>&gt; &gt; 
            value="http://www.somepage.org/ok.htm"&gt;<BR>&gt; &gt; &lt;input 
            type="hidden" name="RECIPIENT"<BR>&gt; &gt; 
            value="someone@somepage.com"&gt;[/color]<BR>&gt;<BR>&gt; This is a 
            /huge/ security risk. Never use a mail form that requires a<BR>&gt; 
            full "To:" address - it's an easy target for spam (both for 
            receiving<BR>&gt; it, and sending it).<BR>&gt;[color=green]<BR>&gt; 
            &gt; &lt;input type="text" name="UserName"<BR>&gt; &gt; size="20" 
            maxlength="60"&gt; &lt;input type="password" name="pw1"<BR>&gt; &gt; 
            size="20" maxlength="60"&gt; &lt;input type="password" 
            name="pw2"<BR>&gt; &gt; size="20" maxlength="60" 
            onBlur="checkPw(this)"&gt;&lt;br&gt;[/color]<BR>&gt;<BR>&gt; The 
            check should really be done upon submission. If I choose to 
            do<BR>&gt; something else before completing a matching password 
            (including<BR>&gt; changing my original password), I'll be trapped 
            in this input field.<BR>&gt; There's also no need to pass the entire 
            object: just pass the value<BR>&gt; using 
            this.value.<BR>&gt;[color=green]<BR>&gt; &gt; &lt;input 
            type="submit" value="Submit Application"<BR>&gt; &gt; 
            onClick="if(this.value == 'Continue') 
            this.form.submit();"&gt;[/color]<BR>&gt;<BR>&gt; From what you've 
            shown, that onclick event doesn't seem to do<BR>&gt; anything. It 
            would have been helpful if you had shown the function<BR>&gt; called 
            by the form's onsubmit event.<BR>&gt;<BR>&gt; Apply the suggestions 
            I've made so far. If it's not enough, say so,<BR>&gt; and include 
            the function called by the onsubmit event and explain<BR>&gt; your 
            restrictions in more detail, and I'll try again.<BR>&gt;<BR>&gt; 
            Good luck,<BR>&gt; Mike[/color]<BR><BR>Hi Mike: Without typing 
            anything on the fields and simply clicking on<BR>submit, IE6 
            errors:<BR>"Line 22, Char 1, Object Expected"<BR><BR>I'm sure I 
            screwed 
            up!:<BR><BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&lt;title&gt;Test Page 
            01&lt;/title&gt;<BR>&lt;META http-equiv="Content-Script-Type" 
            content="text/javascript"&gt;<BR>&lt;script 
            type="text/javascript"&gt;<BR>function checkPw(element) {<BR>pw1 = 
            document.forms['FormName'].elements['pw1'].value;<BR><BR>pw2 = 
            element.value;<BR>if (pw1 != pw2) {<BR>window.alert ("Passwords do 
            not match. Please 
            re-enter.");<BR>document.FormName.pw1.value="";<BR>window.alert 
            ("Please enter a 
            password.");<BR>document.FormName.pw2.value="";<BR>window.alert 
            ("Please re-enter your 
            password.");<BR>document.FormName.pw1.focus();<BR>}<BR>// 
            --&gt;<BR>&lt;/script&gt;<BR>&lt;/head&gt;<BR>&lt;body&gt;<BR>&lt;form 
            action="http://www.photoshelf.net/cgi-bin/mailto"<BR>onsubmit="return 
            FrontPage_Form1_Validator(this)" 
            method="post"<BR>name="FormName"&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"<BR>"this.value"&gt;&lt;br&gt;<BR>&lt;input 

⌨️ 快捷键说明

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