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 8534345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:10:25+00:00 2026-06-11T10:10:25+00:00

I am trying to get a basic data validation working on a form for

  • 0

I am trying to get a basic data validation working on a form for a uni project. However, the javascript function I am trying to call does not seem to be getting accessed at all, and I haven’t been able to figure out why.

Here is my HTML:

<!DOCTYPE HTML>

<HTML>

<HEAD>

<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> 

<TITLE>Make an Order</TITLE>

<link href="design/css/style.css" rel="stylesheet" type="text/css">
<script src="design/scripts/Validator.js" language="javascript" type="text/javascript"></script>

</HEAD>

<BODY>

<div id="container">

    <form id="guestbook" method="post" action="index.html" onsubmit="return Validator(this);">
        <fieldset>
            <legend>
                Personal information
            </legend>
            <label for=name>Name:</label>
            <input id=name name=name type=text placeholder="Your name" required autofocus><br />
            <label for=email>Email:             </label>
            <input id=email name=email type=text placeholder="Your email address" required><br />
            <label for=phnumber>Phone number:       </label>
            <input id=phnumber name=phnumber type=text placeholder="Your telephone number" required><br />
        </fieldset>

        <fieldset>
            <legend>
                Order details
            </legend>
            Choose whether you would like to order an image, video, or both:<br />
            <input id=image name=order_type type=checkbox value="Image"><label for=image>$100 Image:</label><br />
            <input id=video name=order_type type=checkbox value="Video"><label for=video>$95/frame Video:</label><br />
            <label for=url>URL of image to modify:  </label>
            <input id=url name=url type=text placeholder="URL of image" required><br />
        </fieldset>

        <fieldset>
            <legend>
                Credit card details
            </legend>
            <label for=ccnumber>Credit card number:</label>
            <input id=ccnumber name=ccnumber type=text placeholder="Your credit card number" required><br />
            <label for=bsbnumber>BSB number:</label>
            <input id=bsbnumber name=bsbnumber type=text placeholder="Your BSB number" required><br />
        </fieldset>

        <div class="buttons">
            <input type="submit" value="Submit" />
            <input type="reset" value="Reset" />
        </div>

    </form>

    <div id="footer">
        <p>website by etc</p>
    </div>

</div>

</BODY>

</HTML>

And here is my external javascript file, Validator.js:

function Validator(theForm)
{
    var errorinit = "Error(s) detected. Please amend before continuing:\n";
    var error = errorinit;

    //check that at least one checkbox (to choose either image or video) has been selected
    var boxChecked = false;
    if (theForm.image.checked == true && theForm.video.checked == true)
    {
        boxChecked = true;
    }
    if (boxChecked == false)
    {
        error += " - You must select at least a video or an image.\n"
        break;
    }

    //check that numerical-only inputs have numbers (but allowing for habitual spaces or dashes) only
    var digits = "0123456789- ";
    var temp = null;
    for (var i = 0; i < theForm.phnumber.value.length; i++)
    {
        temp = theForm.phnumber.value.substring(i, i+1)

        if (digits.indexOf(temp) == -1 && theForm.phnumber.value != "")
        {
            error += " - Your phone number must be numerical only.\n";
            break;
        }
    }
    for (var i = 0; i < theForm.ccnumber.value.length; i++)
    {
        temp = theForm.ccnumber.value.substring(i, i+1)

        if (digits.indexOf(temp) == -1 && theForm.ccnumber.value != "")
        {
            error += " - Your credit card number must be numerical only.\n";
            break;
        }
    }
    for (var i = 0; i < theForm.bsbnumber.value.length; i++)
    {
        temp = theForm.bsbnumber.value.substring(i, i+1)

        if (digits.indexOf(temp) == -1 && theForm.bsbnumber.value != "")
        {
            error += " - Your bsb number must be numerical only.\n";
            break;
        }
    }

    //check that the email address contains an @ symbol
    if ((theForm.email.value.indexOf ('@',0) == -1 || theForm.email.value.indexOf ('.',0) == -1) && theForm.email.value != "")
    {
        error += " - Your email address is invalid.";
    }

    //check if there has been any error
    if (error != errorinit)
    {
        alert(error);
        return (false);
    } else {
        alert("no problems");
        return (true);
    }
}

Now this is fairly simple code, so and after checking and re-checking I am stumped as to why it is not working. As you can see in the javascript, I have set it to throw an alert whether there has been an error or not, but no alert is given at all; I am simply returned to index.html without any validation (apart from the ‘required’ fields).

Can anybody point out the reason that this is not working?

  • 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-11T10:10:26+00:00Added an answer on June 11, 2026 at 10:10 am

    This is the error that you have in your code:

    SyntaxError: unlabeled break must be inside loop or switch
    

    You are using break; at part below while you aren’t in any switch or loop to break it:

    if (boxChecked == false)
    {
        error += " - You must select at least a video or an image.\n"
        break;
    }
    

    To solve this problem, replace break; with return false; …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a basic flip animation transition working when I push a
I'm trying to get a basic sample across domains working, but I just cannot
I've been trying to get a basic OAuth interaction working without success. There are
I am not trying to get to fancy with my client side validation this
Mornin', I'm trying to just get basic encryption working using System.Security.Cryptography.RjindaelManaged. I have google
I'm trying to get a basic rails app to read data out of a
I am trying to get data from a Google Doc Spreadsheet, using javascript and
I'm trying to get a basic datagrid for simple tabular input. The server will
I am trying to get a basic understanding on how to use fputc in
I'm trying to get started with Three20 and just want to get a basic

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.