javascript - Stop Submit With Empty Input Values -
I'm looking for a simple solution to stop a login form from submitting from the blank input field. The code for is below. If possible, I would like to use a simple JavaScript solution.
& lt; Form id = "login" method = "post" action = "" & gt; & Lt; Input type = "text" name = "email" id = "email" /> & Lt; Input type = "password" name = "pwd" id = "pwd" /> & Lt; Button type = "submit" id = "submit" & gt; Login & lt; / Button & gt; & Lt; / Form & gt;
If possible, I would like to change the range of empty fields.
Thanks in advance.
Sample code with dummy check:
& lt; Script type = "text / javascript" & gt; Function Check Form (Form) {var Mail Check = Checkmail (Form Elements ['Email']), PWD Check = Check Paid (Form.Elements ['PWD']); Return Mail Checkers & amp; PwdCheck; } Function checkmail (input) {var check = input.value.indexOf ('@') & gt; = 0; Input.style.borderColor = Check? 'black Red'; Return check; } Function checkpid (input) {var check = input.value.length & gt; = 5; Input.style.borderColor = Check? 'black Red'; Return check; } & Lt; / Script & gt; & Lt; Style type = "text / css" & gt; # Login Input {Range: 2px solid black; } & Lt; / Style & gt; & Lt; Form id = "login" method = "post" action = "" onsubmit = "return check form (this)" & gt; & Lt; Input type = "text" name = "email" id = "email" onkeyup = "checkMail (this)" /> & Lt; Input type = "password" name = "pwd" id = "pwd" onkeyup = "check pad (this)" /> & Lt; Button type = "submit" id = "submit" & gt; Login & lt; / Button & gt; & Lt; / Form & gt;
Comments
Post a Comment