• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How work this reusable form validation script

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
I had found this javascript code in a book but I do not know how it work, is to say, I do not how call it from my html code!
The book say that I need to call the class : <input type="text" class="email" id="email" name="email" /> o <input type="text" class="required" id="username" name="username"/>
This code is a generical form validator and I find it very helpfull!!
The full code is:

I know how to call function from html but in this code I just see labels!! as : "init", "submitListener", etc
Please can anybody tell me how it work??

Thank you and Excume me my bad english.
 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript is not Java. This has been moved to the HTML and JavaScript forum.

Also, please edit your post to UseCodeTags.
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't it make sense to tell us which book? Right now I'm assuming Simply JavaScript.

Have you tried to understand the code even a little? Hint: you don't call it manually.
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:Wouldn't it make sense to tell us which book? Right now I'm assuming Simply JavaScript.

Have you tried to understand the code even a little? Hint: you don't call it manually.



Yes, Is Simply JavaScript by kevin yank and cameron Adams! specifily the page 250.

Yes I read the article and I am trying to understand this quote in the book about this "The init method is simple enough. All we need to do is add a submit event
listener to every form on the page:
" this is writed before this piece of code :


But I am trying understand if I must to put an onsubmit event in the forms or only a submit button for it work. I suspect that onsubmit wont work because I not see any posible function for to call. I can see that I must to put the property name="form" to every form for the array work.
Sorry but I not understand wht do you mean with " you don't call it manually" ! you mean to put tis line " <SCRIPT src="scripts/validador.js"></SCRIPT>" between head tags?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it?

If you have the book in front of you I'm not sure what the issue is. I'd recommend against just randomly using code you don't understand--what happens if something goes wrong?

In any case, I *don't* have the book in front of me, but on a quick inspection it looks as though as long as you follow the class name conventions and call the init method you're done.
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:Have you tried it?

If you have the book in front of you I'm not sure what the issue is. I'd recommend against just randomly using code you don't understand--what happens if something goes wrong?

In any case, I *don't* have the book in front of me, but on a quick inspection it looks as though as long as you follow the class name conventions and call the init method you're done.



The book is the first edition. The book have not "if something goes wrong" section.!

The book explain very well the code but the book not explain how to call the script from a html code !!! that is my problem. I tried all the ways that I know and nothing! and my confussion with this code is that I not see a function as : example() then I could to call it as ; onclick="example()" or in a form onsubmit="example()"

thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, you don't do anything directly, except call the init method, and make sure you (a) follow the class name conventions, and (b) have the appropriate element type/name as needed by the init method.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic