Validation not working (only one item)

On the attached file - ALL items in the enclosed form are being validated properly except one (AMPM field) - It is a radio button and that is the only difference? The code is at lines 361 and 947.
Who is Participating?
Julian HansenCommented:
You are using this to get the value of the radio button

var ampm = document.getElementById('ampm').value;

Which is not going to work - also you have duplicated id's for the radio button so it is even more difficult.

1. Give each of the radio button's a unique id
2. Check the value of the radio button's to see which is checked like so

if (document.getElementById('ampm1').checked)
  ampm = document.getElementById('ampm1').value;
else if (document.getElementById('ampm2').checked)
  ampm = document.getElementById('ampm2').value;

Open in new window

You might want to consider using JQuery as well - it makes this sort of code a lot easier.
Kyle HamiltonData ScientistCommented:
first of all, you cannot have twoelements with the same id, namely ampm. your js will wig out for that reason alone.

second, you're checking for the wrong value - the values of your radio buttons are "AM" and "PM", not "Ex:3:30"

third, dont check for the value, but for wether a radio is selected or not.

thats a start. if you need more help, just let us know.

edavoAuthor Commented:
best solution:

else if(ampm3 == '' && ampm4 == ''){

               alert("Please Enter Your AM/PM");
                  document.getElementById('ampm3' || 'ampm4').focus();

               return false;

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.

All Courses

From novice to tech pro — start learning today.