Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9269975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:15:25+00:00 2026-06-18T15:15:25+00:00

I’m having a little problem with a validation thing in javascript. <form action=insert.php id=form

  • 0

I’m having a little problem with a validation thing in javascript.

<form action="insert.php" id="form" name="form" method="post" 
    onSubmit="return validate()">
    <pre>
        Vul hier de/het E-mail adres(sen) in
        <textarea name="email" rows="5" cols="50"></textarea><br>
        Typ hier de E-mail
        <textarea name="text" rows="5" cols="50"></textarea><br>
        <input type="submit" name="Submit" value="Submit">
    </pre>
</form>

As you can see here, I’ve got two textareas. In the upper one, you’re supposed to enter one or multiple email addresses underneath eachother, and in the bottom textarea you’re supposed to compose the email itself. Then, when you click on submit, it’ll send the email to all those specified email addresses.

Now, I’ve made a validation for both textareas:

function explodeArray(emailID, delimiter) {
    tempArray = new Array(1);
    var Count = 0;
    var tempString = new String(emailID);

    while (tempString.indexOf(delimiter) > 0) {
        tempArray[Count] = tempString.substr(0, tempString.indexOf(delimiter));
        tempString = tempString.substr(
            tempString.indexOf(delimiter) + 1, 
            tempString.length - tempString.indexOf(delimiter) + 1
        );
        Count = Count + 1
    }

    tempArray[Count] = tempString.replace("\r", "");
    return tempArray;
}

function validate() {
    var emailID = document.form.email;
    var delimiter = "\n";
    var emailArray = explodeArray(emailID.value, delimiter);
    var textID = document.form.text;
    var length = emailArray.length,
        element = null;
    for (var i = 0; i < length; i++) {
        emailVar = emailArray[i];

        if (emailVar == null) {
            alert("Email-adres bestaat niet")
            emailID.focus()
            return false
        }
        if (emailVar == "") {
            alert("Email-adres veld is leeg")
            emailID.focus()
            return false
        }
        if (checkEmail(emailVar) == false) {
            emailVar.value = ""
            alert("Ongeldig E-mail adres");
            emailVar.focus()
            return false
        }
    }
    if ((textID.value == null) || (textID.value == "")) {
        alert("E-mail textveld is leeg")
        textID.focus()
        return false
    }
    document.getElementById("form").submit();
    return true
}

function checkEmail(hallo) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(hallo)) {
        return true
    }
    return false
}

(I probably copied lots of irrelevant code as well, sorry for that, just copied the whole thing just in case…)

Now what does work is:

-it won’t submit when both textareas are empty;

-it won’t submit when the email addresses are valid but the bottom textarea is empty;

What doesn’t work is:

-the form still submits when the email addresses are invalid, even when the bottom textarea is still empty.

I’ve been trying to figure out for hours what could possibly be wrong here, I googled and checked stackoverflow, but I really could not find anything. Could anybody tell me what I’m doing wrong here?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:15:27+00:00Added an answer on June 18, 2026 at 3:15 pm

    You were using emailVar.focus(); which won’t execute.

    Here, fixed: Live Demo

    if (checkEmail(emailVar) == false) {
        alert("Ongeldig E-mail adres");
        emailID.focus();
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.