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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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
geeta_m9Author Commented:
I added the semicolons to the functions and included a window.onload function but there is still no difference.
You're still missing it after this line:
btnClear.onclick = function() {
            emailTxt.value = "";
            passwdTxt1.value = "";
            passwdTxt2.value = "";
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

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

Live sample:


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.
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

From novice to tech pro — start learning today.