2

I will be brief, but try to give you a good idea of what I need through a smaller example.

I have 3 boxes of information: one text, one starting time and one ending time.

Every day someone will input some "activities" they did throughout the day. For instance "Mowed the Lawn" (text input), Starttime=10:00am (select input) - Endtime=11:00am (select input).

However I have built into this webpage the ability to click on a button and it will add another 3 inputs (activity, starttime, endtime) for all the activities they did through the day. If it helps, I have this structured so that the name of these inputs are for example activity[], starttime[], endtime[] so that PHP will render it correctly and store the values appropriately in the database.

My goal is that I don't want to put bad time data into my database (starttime = 10:00am, endtime = 9:00am. I understand how to do form validation for 1 instance of the 3 inputs (getElementById has done this for me), but not multiple instances of the three inputs in a dynamic array.

Thoughts?

Here's a link to a screenshot (since I'm a new user and can't post images). http://admissions.utils.us/images/Screenshot.png

0

1 Answer 1

1

you could check to see how many elements on the page have the tag and then do a for loop to cycle through the array of input elements and then do your verification

var inputs = document.getElementsByTagName('input').length;

for (var i = 0; i < inputs; i++){
    if (document.getElementsByTagName('input')[i].value != ''){
        return true;
    } else {
        return false;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.