Cannot get onblur function to work in JavaScript

I am trying to use JavaScript in Dreamweaver to validate a form input. What I would like to do is to have the person enter an email address and a password in the "Password" textbox and the same password again in the "Verify Password" texbox. If the user clicks on the email textbox and then leaves it without entering a value then an alert should be displayed reminding the user to enter a value for the email and setting the focus back to the email textbox. The same goes for the "Password" and "Verify Password" textboxes. Once the user clicks away from the "Verify Password" texbox, the code should compare the values in the "Password" and "Verify Password" textboxes. If they are the same, then it should display an alert to that effect. Otherwise, it will shown an error and return the focus back to the "Password" textbox.

Currently, I can only get the "Clear" button to work. The rest of the code doesn't work at all and I don't know why. I am new to JavaScript.

I would appreciate any help.
setpassword.html
Lab5.js
Form.jpg
geeta_m9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

themrrobertCommented:
You need a semicolon after each of the function definitions.

Remember, you're making an assignment statement:

myObject.onblur = function() { function code... };

do not forget the semi colon.

Also, you may want to add a timer, or use jquery, or some other javascript (like window.onload) to make sure the code doesn't run until after the full page is loaded.

After syntax errors, javascript running too fast is the next leading cause of failures like this :p
0
geeta_m9Author Commented:
I added the semicolons to the functions and included a window.onload function but there is still no difference.
Lab5.js
0
themrrobertCommented:
You're still missing it after this line:
btnClear.onclick = function() {
            emailTxt.value = "";
            passwdTxt1.value = "";
            passwdTxt2.value = "";
      }
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

geeta_m9Author Commented:
Thanks. I added the semicolon but still no difference.
0
Rainer JeschorCommented:
Hi,

the issue is that you have to call your prepareEventHandlers AFTER the HTML DOM has been loaded.

Live sample:
https://jsfiddle.net/EE_RainerJ/3wdg14c7/

HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
geeta_m9Author Commented:
I realized the problem was caused by:

1. I did not put the JavaScript tag in the header section of the HTML file, i.e.,  <script src="Lab5.js"></script>

2. My document.getElementById call was not using the right case. I had it as "getElementByID" in some parts of my code.

Thank you for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.