/    Sign up×
Community /Pin to ProfileBookmark

How to prevent this event not to occur before validation password is not done?

`document.getElementById(“submit”).addEventListener(“click”,function checkpwd(){
var password=document.getElementById(‘password’).value;
if(password.length<8)
{
alert(“Your password must be at least 8 characters”);

return false;
}

return false;
});`

to post a comment
HTMLJavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@NachfolgerOct 14.2020 — The context you have provided thus far will not suffice. You're already "validating" the password here, are you trying to prevent the submit event from processing?

``Javascript<i>
</i>document.getElementById("submit").addEventListener("click", function(e) {
if (document.getElementById('password').value.length &lt; 8) {
alert("Your password must be at least 8 characters");
e.preventDefault();
}
});<i>
</i>
`</CODE>

Call <C>
preventDefault` on the event object.
Copy linkTweet thisAlerts:
@VITSUSAOct 15.2020 — @Mohanprasath#1624209 I agree with Nachfolger, you're already "validating" the password here, are you trying to prevent the submit event from processing?
×

Success!

Help @Mohanprasath spread the word by sharing this article on Twitter...

Tweet This
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...