Form validation using Javascript on the client side for beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ค. 2024
  • In this video, we will create a client-side #form #validation using #javascript. I'll only use vanilla javascript and no external 3rd party dependencies. The aim is to help beginners to do form validation and understand how the whole process works.
    Website: www.javascriptacademy.dev/
    Source code: codepen.io/javascriptacademy-...
    ⏱Timestamps:
    00:00 Intro
    00:26 HTML
    03:33 CSS
    05:35 Javascript
    Where you can find me?
    🔗 Links:
    * 🍺 Support free education and buy me a beer: ko-fi.com/adamnagy
    * 💬 Discord: / discord
    * 📧 Newsletter: www.getrevue.co/profile/dev_a...
    * ✍️ Blog: dev.to/javascriptacademy
    * 🐦 Twitter: / dev_adamnagy
    * 📷 Instagram: / javascriptacademy

ความคิดเห็น • 141

  • @mohammedanafm
    @mohammedanafm 5 หลายเดือนก่อน +2

    Form validation using javascript was so difficult but thanks to this simple explanation, I was able to get an idea of how it works.

  • @zoirradjabov1420
    @zoirradjabov1420 ปีที่แล้ว +8

    Simple and effective! That exactly what I needed

  • @JsAcademyOfficial
    @JsAcademyOfficial  ปีที่แล้ว

    New web development tutorial from me: Memory card game using Javascript, HTML, and CSS: 🔥
    th-cam.com/video/xWdkt6KSirw/w-d-xo.html

  • @CLICK4CAST
    @CLICK4CAST 2 ปีที่แล้ว

    hi, i am getting " Uncaught TypeError: Cannot read properties of undefined (reading 'querySelector') " it is showing at setError() line number. can you help me

  • @hunterzone4846
    @hunterzone4846 ปีที่แล้ว +1

    Thanks for this. You explained everything clearly.

  • @vladropotica5687
    @vladropotica5687 ปีที่แล้ว +1

    Thank you very much. I recently started learning JavaScript, this video is the first video in 4 consecutive ones that finally worked (for me at least) without problems that i didn't know how to solve.

    • @JsAcademyOfficial
      @JsAcademyOfficial  ปีที่แล้ว +1

      That’s really great to hear! I’m glad I could help 😉

  • @photoinshot1355
    @photoinshot1355 ปีที่แล้ว +5

    Thanks for a great tutorial! How do you get the form to submit if it passes validation?

  • @hyllaf
    @hyllaf ปีที่แล้ว

    would anyone know - whilst creating a SIGN UP FORM - how to get the submit button the same exact size at the input boxes?

  • @Shalamandez
    @Shalamandez 2 ปีที่แล้ว +1

    Thanks for this video. So simplified

  • @m.j.mcintear793
    @m.j.mcintear793 ปีที่แล้ว

    how to call the function with each of these variables as an argument emailaddress variable and emailconfirm variables
    Do you know how to make two of the same emails need to match and is that client side validation or server side? Inquiry of js on html form

  • @gorreon
    @gorreon 3 หลายเดือนก่อน

    Thank you so much for this great tutorial! Saved me a lot!

  • @wajry
    @wajry ปีที่แล้ว

    Brief and helpful, thanks!

  • @mikensonpierre2029
    @mikensonpierre2029 2 ปีที่แล้ว +1

    Would it be an issue if we use the same div class = "input-control" instead of creating multiple and just changing the id and name?

  • @tonytony-fc6gq
    @tonytony-fc6gq ปีที่แล้ว +2

    HOW DO YOU clear the input field after successful submit??

  • @hishamrabea566
    @hishamrabea566 3 หลายเดือนก่อน +1

    Bro greatings from Egypt!
    You are great you helped me really ❤

  • @guillermomazzari4983
    @guillermomazzari4983 ปีที่แล้ว

    Thanks a lot!! This was very useful!!!

  • @Blessed-d8r
    @Blessed-d8r 28 วันที่ผ่านมา

    How do you write the exponential symbol?

  • @IPlayWhatiLike
    @IPlayWhatiLike ปีที่แล้ว +12

    Great video. Short, to the point, and well explained.

  • @janakiramanjohn4753
    @janakiramanjohn4753 ปีที่แล้ว

    Great video bro,thank you very much

  • @justrising4027
    @justrising4027 10 หลายเดือนก่อน +1

    Please can anyone help with making the form submit?

  • @user-lg7vm2eo1v
    @user-lg7vm2eo1v 5 หลายเดือนก่อน

    Simple and understandable. Thanks

  • @ooooo5598
    @ooooo5598 2 ปีที่แล้ว

    how can i go to other page if i click

  • @OliaYarukhina
    @OliaYarukhina ปีที่แล้ว

    Cool! Thank you so much!

  • @sh9vch9nk0
    @sh9vch9nk0 4 หลายเดือนก่อน

    Very useful video and clear explanations, thank you for this tutorial 💗💗

  • @visenyaa19
    @visenyaa19 ปีที่แล้ว

    thank you so much for your great video

  • @evangelistaa.r.8242
    @evangelistaa.r.8242 2 ปีที่แล้ว +5

    Thank you for this tutorial it helped me a lot😊

  • @Demon_T8_
    @Demon_T8_ 2 หลายเดือนก่อน

    will this be saved ? i want to login with the signed id and password only

  • @MBXD001
    @MBXD001 4 หลายเดือนก่อน

    Very helpful video, for me this worked, nothing else was working

  • @web__designerr
    @web__designerr ปีที่แล้ว

    how to redirect the next page

  • @MohamedAli-nn5ld
    @MohamedAli-nn5ld ปีที่แล้ว

    Amazing video!

  • @viniciusm.m.7822
    @viniciusm.m.7822 ปีที่แล้ว

    Wow
    Thanks, man!

  • @alwayshibu
    @alwayshibu 2 ปีที่แล้ว

    very helpful turorial.

  • @shankysontakke3253
    @shankysontakke3253 2 ปีที่แล้ว +3

    This is so 👍 great Need more videos on javascript...

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 ปีที่แล้ว +2

      Thanks for the kind words Shanky!
      A few more videos are in progress, in the meanwhile you can check my other videos on javascript 😉

  • @zachfenton608
    @zachfenton608 2 ปีที่แล้ว +1

    Very well done. May I use the code in my project. I will add on to it.

  • @jeo8007
    @jeo8007 ปีที่แล้ว

    why i cant submit the form??

  • @igraphicsalliance
    @igraphicsalliance 6 หลายเดือนก่อน

    it's work but the form not work (PHP) why?

  • @HienTran-lo3jh
    @HienTran-lo3jh 3 หลายเดือนก่อน

    thank you bro thumbs up

  • @christianjack1250
    @christianjack1250 หลายเดือนก่อน

    Great job

  • @ahmetbiba2489
    @ahmetbiba2489 ปีที่แล้ว

    Thank you so much everything is working but i need a little help at the submit button i have to make a link to anther page after i fill all the boxes is it possible.

    • @JsAcademyOfficial
      @JsAcademyOfficial  ปีที่แล้ว

      You can use the action attribute of the form element or you can send an xmlhttprequest to any backend endpoint

  • @user-hj6en4be1f
    @user-hj6en4be1f 5 หลายเดือนก่อน

    Thank you so much.....

  • @n0lame
    @n0lame ปีที่แล้ว +2

    does anyone know how I would be able to transfer the information gathered from this form into MySQL using XAMPP? I've never used these programs before and I'm confused

    • @mahek9015
      @mahek9015 วันที่ผ่านมา

      event I need this! Did u find the solution?

  • @johnajil6379
    @johnajil6379 5 หลายเดือนก่อน

    Thank you

  • @AkshaPatel-hy7qo
    @AkshaPatel-hy7qo 3 หลายเดือนก่อน

    Subscribed!

  • @rameshxml
    @rameshxml 2 ปีที่แล้ว +1

    Thank you for this but my out put is not coming if i click the button it will show the c: drive can you pls suggest

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 ปีที่แล้ว

      Feel feee to check the source code in the description, there must be a typo in your code

    • @chukwuebukaobiajulu2849
      @chukwuebukaobiajulu2849 2 ปีที่แล้ว

      Don't know if you found a solution yet, but in your HTML, your form tag, just delete everything else in there and use only id="id name"

  • @ishaanapte6570
    @ishaanapte6570 ปีที่แล้ว

    thanks😀

  • @youtubepv
    @youtubepv 2 ปีที่แล้ว

    Thnks😊

  • @Aut-O-Mizer
    @Aut-O-Mizer 2 ปีที่แล้ว

    How did you space out the text boxes without using any margin settings

    • @fidelisitor8953
      @fidelisitor8953 2 ปีที่แล้ว +1

      the spacing was added from the height of the .error div

    • @Aut-O-Mizer
      @Aut-O-Mizer 2 ปีที่แล้ว

      @@fidelisitor8953 Thanks bro

  • @boky7731
    @boky7731 ปีที่แล้ว +1

    Hey, so how to stop preventDefault() from executing if the inputs are valid?

    • @north4220
      @north4220 ปีที่แล้ว

      did you find a solution please .?

    • @mahinpatel8024
      @mahinpatel8024 ปีที่แล้ว +5

      if (document.querySelectorAll('.success').length === 4) {
      // submit the form
      form.submit();
      }
      // You can submit the form if all the inputs are valid by adding a line of code after the validation checks inside the validateInputs function.

    • @narikodanhridul2845
      @narikodanhridul2845 9 หลายเดือนก่อน

      form.addEventListener('submit', (e) =>{
      var flag = 1;
      if(name.value === ''){setError(name, "Username is required"); flag=0;
      }else{setSucces(name)}
      if(email.value === ''){setError(email, "email is required"); flag=0;
      }else{setSucces(email)}
      if(password.value === ''){setError(password, "Password is required"); flag=0;
      }else if(password.value.length < 8){setError(password, "Password must be atleast 8 charecter"); flag=0;
      }else{setSucces(password)}
      if(password2.value === ''){setError(password2, "Please confirm password"); flag=0;
      }else if(password.value != password2.value){setError(password2, "Password should be same"); flag=0;
      }else{setSucces(password2)}
      if(flag === 0){ e.preventDefault(); }
      })

  • @MichaelWarmer
    @MichaelWarmer ปีที่แล้ว

    how do i remove e.preventDefault() after validation so it move to the next page... thank you

    • @JsAcademyOfficial
      @JsAcademyOfficial  ปีที่แล้ว

      I’m planning to release a tutorial about it soon, you have some options in the form you can set the action which accepts a url and then you need to have a backend configured to handle the data from your form

  • @realitystevens
    @realitystevens ปีที่แล้ว +26

    The form will not submit until you add the submit functionality below the validateInputs(); function.

    • @Itsamoudim
      @Itsamoudim ปีที่แล้ว +3

      you mean the validateInputs(); bellow the submit functionality

    • @uhk2150
      @uhk2150 ปีที่แล้ว +1

      How to solve this issue..

    • @north4220
      @north4220 ปีที่แล้ว +1

      @@uhk2150 did you solve it please ?

    • @mihrettekalgn9492
      @mihrettekalgn9492 ปีที่แล้ว +5

      Just put the 'defer' key word in the script tag that will solve the problem

    • @sarat4695
      @sarat4695 ปีที่แล้ว

      @@mihrettekalgn9492 can you please explain to me where to put it specific

  • @AP_Singh
    @AP_Singh 2 ปีที่แล้ว +5

    how does the script know when every input is validated and its time to stop preventing the default action of 'submit' ??

    • @chrischti
      @chrischti 2 ปีที่แล้ว +8

      Don't use the prevent submit function in the java script, instead run the function from the form, by adding onsubmit="return validateForm()", by that the form will be submitted if the function returns true

    • @sanjeetlal1873
      @sanjeetlal1873 2 ปีที่แล้ว +1

      @@chrischti works!! Thank you perfect

    • @casesensitive9744
      @casesensitive9744 9 หลายเดือนก่อน

      I found the solution. submit() is a method. It will just eleminate preventDefault and just submit the form.

  • @madebytl
    @madebytl 2 ปีที่แล้ว +1

    Hi, there how can we do with onClick(); when button have clicked?

    • @bzoxx
      @bzoxx 2 ปีที่แล้ว

      I know it's been 2 months but...
      You just assign the attribute
      Onclick = yourfunc()

    • @madebytl
      @madebytl ปีที่แล้ว

      @@bzoxx Thank! but what if we didn't fill the form already and then click on button.

  • @rodynamuhammadgalal8382
    @rodynamuhammadgalal8382 ปีที่แล้ว

    what about when validating radio buttons and dropdown lists?

    • @kevinrwema9669
      @kevinrwema9669 5 หลายเดือนก่อน

      you don't need to worry about validating radio buttons ant select list. users can only select from the options you've predefined upon creating

  • @Raj-iz9uz
    @Raj-iz9uz 2 ปีที่แล้ว +5

    Superb 🔥
    need JavaScript Crash Course 🙏🏻😊
    pls cover the JS Topic's required to Start with React or Angular 👍

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 ปีที่แล้ว +5

      Thanks for the feedback!
      It would be great to create a crash course, unfortunalely I don’t have time to create it now (this year), but it is definetely on my list now.

    • @ariyansgroup
      @ariyansgroup 2 ปีที่แล้ว

      We are waiting for it..

  • @nelmarkjhonduarte4040
    @nelmarkjhonduarte4040 ปีที่แล้ว

    can you make tutorial this form validation with firebase, it will be so helpful to others if make that :(

  • @louizamariakonizari2022
    @louizamariakonizari2022 2 ปีที่แล้ว +1

    Could you please help me to understand my mistake? I have the following code:

    dokimastiko



    and this is my js code
    let y = getElementById('onoma').value;
    and it gives me a reference error getelementbyid("onoma").value; is not defined.
    What am I doing wrong? Thank you.

    • @chrischti
      @chrischti 2 ปีที่แล้ว +3

      Correct is: let y = document.getElementById('onoma').value

  • @AP_Singh
    @AP_Singh 2 ปีที่แล้ว

    I am using javascript function to submit form data. So, how can call it only after validating inputs?

  • @ernesto8273
    @ernesto8273 2 ปีที่แล้ว

    All went well. Please what do I need to do if I want to add an icon on the error validation?

    • @voldy9918
      @voldy9918 ปีที่แล้ว

      Hi, do u finally got this?? explain me pls!

  • @duypkthg592
    @duypkthg592 ปีที่แล้ว

    Nice🥰

  • @gracefool1786
    @gracefool1786 2 ปีที่แล้ว +2

    why have a validation form tutorial where the submit button doesnt work T.T

    • @realitystevens
      @realitystevens ปีที่แล้ว

      The form will not submit until you add the submit functionality below the validateInputs(); function.

    • @alexanderjackson7815
      @alexanderjackson7815 ปีที่แล้ว +1

      @@realitystevens Okay, but what if your using php for the backend and want to actually submit for it to work, I guess its better to use something else

  • @Duckergg.j
    @Duckergg.j ปีที่แล้ว +1

    It doesn't work when I submit with the button 👎

  • @kahlschlag17
    @kahlschlag17 2 ปีที่แล้ว

    querySelectro('.error)'; ....why the dot?

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 ปีที่แล้ว

      It mean that the error is a Html class

    • @kahlschlag17
      @kahlschlag17 2 ปีที่แล้ว +1

      @@JsAcademyOfficial thanks mate.

  • @chiennguyen4652
    @chiennguyen4652 2 หลายเดือนก่อน

    Where is source code?

  • @MAjay-qh1xd
    @MAjay-qh1xd 2 ปีที่แล้ว +2

    Nice

  • @saiyannaingx6416
    @saiyannaingx6416 2 ปีที่แล้ว

    After validating and theres no error but the submit button not working anymore. how do i fix this

    • @lailaayman1040
      @lailaayman1040 2 ปีที่แล้ว

      i want to know how too

    • @chrischti
      @chrischti 2 ปีที่แล้ว +1

      Don't use the prevent submit function in the java script, instead run the function from the form, by adding onsubmit="return validateForm()", by that the form will be submitted if the function returns true

    • @sankalpsingh9386
      @sankalpsingh9386 2 ปีที่แล้ว

      @@chrischti this not working

    • @njmust
      @njmust 2 ปีที่แล้ว

      how to submit if validations are true....

  • @khensanimatjokana5843
    @khensanimatjokana5843 ปีที่แล้ว

    css part was a bit blury at the end but good video

  • @polnapanda4934
    @polnapanda4934 11 หลายเดือนก่อน

    Godly

  • @tienskz.official
    @tienskz.official ปีที่แล้ว +1

    Basically, this method does not prevent the button from submitting a form even after the validation of all input controls.

    • @casesensitive9744
      @casesensitive9744 9 หลายเดือนก่อน

      Yes. Please do you know how to override the preventDefault if all requirements is reached? .

    • @narikodanhridul2845
      @narikodanhridul2845 9 หลายเดือนก่อน

      form.addEventListener('submit', (e) =>{
      var flag = 1;
      if(name.value === ''){setError(name, "Username is required"); flag=0;
      }else{setSucces(name)}
      if(email.value === ''){setError(email, "email is required"); flag=0;
      }else{setSucces(email)}
      if(password.value === ''){setError(password, "Password is required"); flag=0;
      }else if(password.value.length < 8){setError(password, "Password must be atleast 8 charecter"); flag=0;
      }else{setSucces(password)}
      if(password2.value === ''){setError(password2, "Please confirm password"); flag=0;
      }else if(password.value != password2.value){setError(password2, "Password should be same"); flag=0;
      }else{setSucces(password2)}
      if(flag === 0){ e.preventDefault(); }
      })

  • @bankoledada
    @bankoledada ปีที่แล้ว

    your website seems to be down - tried visiting and no joy. Great video

    • @JsAcademyOfficial
      @JsAcademyOfficial  ปีที่แล้ว

      It should be up I’ve just tested it. Please try it like this: www.javascriptacademy.dev

  • @victormuturi618
    @victormuturi618 7 หลายเดือนก่อน

    Rien compris

  • @erensancar4381
    @erensancar4381 ปีที่แล้ว

    does not work

  • @johnerickmarzo7278
    @johnerickmarzo7278 2 ปีที่แล้ว

    Lesson from udemy

  • @casesensitive9744
    @casesensitive9744 9 หลายเดือนก่อน

    This whole this is very blurry did he had to assign the valuateInputs to a variable bacause just the name can be a the name. 😄

  • @kgamer5842
    @kgamer5842 ปีที่แล้ว

    i bet this fella is Hungarian

  • @hexor8851
    @hexor8851 ปีที่แล้ว

    gj

  • @jianpatricio7196
    @jianpatricio7196 ปีที่แล้ว +1

    For validation purpose this video is informative, but when in comes to submission 👎 the guy did not give a tutorial on how to submit the form, which is the main purpose of form validation. The guy just focus on ui/ux validation output. So if you're beginner this tutorial is no good, especially if you want to submit the form.

    • @JsAcademyOfficial
      @JsAcademyOfficial  ปีที่แล้ว +1

      I'll release a tutorial soon where I'll show you how you can submit the form and process it on the server-side (nodejs). Stay tuned.

  • @sajiyasulthana4849
    @sajiyasulthana4849 ปีที่แล้ว

    😭😭

  • @MarshGames
    @MarshGames 2 ปีที่แล้ว

    bro you go so fast pls slow down for the newbies here

  • @Dake6i
    @Dake6i 2 ปีที่แล้ว +1

    Русскоговорящий что ли?

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 ปีที่แล้ว +1

      нет, I'm hungarian :)

    • @Dake6i
      @Dake6i 2 ปีที่แล้ว

      @@JsAcademyOfficial Madiyar?

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 ปีที่แล้ว

      Yes, magyar :)

    • @Dake6i
      @Dake6i 2 ปีที่แล้ว

      @@JsAcademyOfficial I'm Kazakh. Kazah vagyok:)

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 ปีที่แล้ว +1

      That’s a nice place, welcome abroad!

  • @manojsunar192
    @manojsunar192 9 หลายเดือนก่อน

    This is not for beginners for sure 😅😂

  • @darlingfans8538
    @darlingfans8538 9 หลายเดือนก่อน

    Total code copy and paste worest class

  • @lucianlsd3274
    @lucianlsd3274 9 หลายเดือนก่อน

    For beginners my ass, i ve seen dozens of forms with js and this is not beginner level pffff BS

  • @olga_lc
    @olga_lc 2 ปีที่แล้ว

    Thanks a lot, that was useful!