• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 555
  • Last Modified:

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.
2 Solutions
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;


Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now