Javascript: Validate textboxes to ensure one textbox has a specific string


I'm trying to have javascript ENSURE that one of the autogenerated textboxes has a string called 'email'. The catch is it COULD be any of the textboxes.

The textboxes are created depending on the number of elements in a php array.. So:

<form action="index.php" method="post" name="importList">
foreach ($headerGrabbed as $headerElement) {
            '<tr class="'.((++$tr)%2==1?"rowdark":"rowlight").'"><td>'.$headerElement.' </td><td>
                        <input id="'.$headerElement.'" value=\''.$headerElement.'\' name=\'headerListElement["'.$headerElement.'"]\'></td>
                        <td><input type="checkbox" value="1" id="'.$headerElement.'X2" name=\'headerListElementX2["'.$headerElement.'"]\'></td>
<input type="submit" class=button value="Start Import" name="submitXc">

Would be the general idea here. All the textboxes end up in a array called 'headerListElementX2' in this case.

What I want to do is check through ALL of them when submit is entered, and make sure one of them has the value of 'email' (Typically this is added by default but they may change it). How could this be done, is it possible using the coding above? Thanks
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.

If you just want to see if a parameter exists in the POST vars, simply use:

if (isset($_POST["email"])) {
   //do some stuff

That will tell you if there is any input named "email" in the submitted form. Is that what you're after? It's a little hard to tell.
I am assuming you want client side validation before submitting:

Change the submit to just a button and use an onclick event to submit:
<input type="button" class=button value="Start Import" name="submitXc" onclick="if (testEmail()) {document.form.importlist.submit();}">

Open in new window

Then the script goes in the head
<script type="text/javascript">
function testEnail()
   testSet= document.getElementsByTagName('INPUT');
   for(i=0;i<testSet.length; i++)
        if (testSet.value='email')
            return true;
    // you probably want a message to the user here
    return false;

Open in new window



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
VallerianiAuthor Commented:
document.getElementsByTagName('INPUT');, works awesome!!! Thank you very much!

This is what I needed!
Glad we could 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.