Error Found: Syntax Error - 'if' statement not recognized

if (fname == null || fname == "") {

Receiving an error message "uncaught syntax error:unexpected token if in line 13". The error indicates "SyntaxError: missing variable name" when using Javascript lint

function validateRegistration() {

    var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;    
    var fname = document.form.user_firstname.value,
        lname = document.form.user_lastname.value,
        uname = document.form.username.value,
        femail = document.form.email.value,
        freemail = document.form.verify_email.value,
        fpassword = document.form.password.value,


        if (fname == null || fname == "") {
            document.form.user_firstname.focus();
            document.getElementById("errorBox")
                .innerHTML = "Please enter a first name";
            return false;
        }
    if (lname == null || lname == "") {
        document.form.user_lastname.focus();
        document.getElementById("errorBox")
            .innerHTML = "Please enter a last name";
        return false;
    }

    if (femail == null || femail == "") {
        document.form.email.focus();
        document.getElementById("errorBox")
            .innerHTML = "Please enter an email";
        return false;
    } else if (!emailRegex.test(femail)) {
        document.form.Email.focus();
        document.getElementById("errorBox")
            .innerHTML = "Please enter a valid email";
        return false;
    }

    if (freemail == null || freemail == "") {
        document.form.verify_email.focus();
        document.getElementById("errorBox")
            .innerHTML = "Please re-enter the email";
        return false;
    } else if (!emailRegex.test(freemail)) {
        document.form.enterEmail.focus();
        document.getElementById("errorBox")
            .innerHTML = "Please re-enter a valid email";
        return false;
    }


    if (fpassword == null || fpassword == "") {
        document.form.password.focus();
        document.getElementById("errorBox")
            .innerHTML = "Please enter a password";
        return false;
    }    

}

Answer №1

There is an issue with the termination of the var statement in this line:

fpassword = document.form.password.value,

To correct it, add a semicolon at the end of the line:

fpassword = document.form.password.value;

if (fname == null || fname == "") {

Answer №2

the password variable declaration (fpassword) concludes with a comma

Answer №3

Revise the following segment:

    fpassword = document.form.password.value; // <--


    if (fname == null || fname == "") {

Answer №4

invalid variable declaration

let firstName = document.form.user_firstName.value,
        lastName = document.form.user_lastName.value,
        username = document.form.usernameEntry.value,
        userEmail = document.form.emailAddress.value,
        verifyEmail = document.form.confirm_email.value,
        userPassword = document.form.passCode.value;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Glitch found in Safari involving innerText of elements

Hey everyone, I posted this question not too long ago but now I have some images to share regarding the issue with Safari. When checking the console in Safari, the following text is displayed: <div id="rot3posDisp" class="rotDisp">C</div> Ho ...

Uniform Image Sizes in Bootstrap Carousel (With One Exception)

I am encountering a JavaScript exception related to image size. I am trying to set a fixed size for the images in my carousel, allowing them to auto adjust or resize without concern for distortion or pixelation. I have experimented with max-width and widt ...

Encountering an error when trying to access a property of an undefined MVC model in a

Embarked on a journey to learn web service development, only to encounter a roadblock. I'm struggling to figure out how to utilize ExpressJS Router() to pass POST data to the controller files. Upon inspecting the request redirected from product.route. ...

Resetting forms in AngularJS 1.5.6 with ng-messages functionality

I have been searching for solutions on Stackoverflow regarding how to reset a form, but I am still not able to figure it out. Even though the input was valid, the error message kept showing up. Upon debugging the application, I noticed that the message was ...

Struggling with NodeJs POST request issue

Let's imagine I have a specific URL https://exampleAPI.com/authorize?param1=value1&param2=value2 Where param1 and param2 are the payload values being sent. How can I execute a POST request in this particular way? I attempted the following: var ...

Tips for adding new items to a Masonry Image List using React MUI

As I experiment with utilizing the React MUI Masonry Image List alongside the infinite scroll, I've found that they complement each other quite well. However, a challenge arises when appending new images to the Masonry image list. While I can success ...

The link tag cannot be used inside a division element

I am facing an issue with a button that has three different states represented by images. While the button looks great and functions well, it fails to perform its primary function - linking to another document. Upon clicking the button, no action is initi ...

Using Node.js for HTML redirections involves creating routes and setting

I am currently attempting to connect my Node.js API with my HTML pages. For the most part, everything is functioning correctly, but I have encountered some confusion along the way. Is there a more efficient method for redirecting an HTML page? Typically, ...

Is there a way to make changes to a pre-uploaded PDF document?

I'm looking to include a footer in a PDF file that is currently stored on the server. For instance, I have uploaded a file to uploads/aaa.pdf and now I need to insert a footer into the same file located at uploads/aaa.pdf Does anyone know how I can ...

Displaying client-side filtered rows in a jqGrid with postData filter upon initial loading

Our website includes a jqGrid that initially retrieves its rows using the built-in ajax fetch feature, returning a json object. We then apply filtering and searching on the client side by creating custom functions to generate postData filters. However, we ...

Accessing the background page of a Chrome extension while it's in operation

I am in the process of developing my first chrome extension that allows youtube.com/tv to run in the background so it can be accessed easily on a phone or tablet. Everything is working fine, except for the fact that if I want to watch the video and not j ...

Reorganize the JSON data to match the specified format

{ "EUR": { "Description": "", "Bid": "1.1222", "Region": "", "Bid1": "1.1283", "CurrencyCode": "EUR", "FeedSource": "1", "Ask": "1.1226", "ProviderName": "TEST 1", "Low": "1.1195", ...

If the form is empty, clicking on the Login button will direct you to the page. It is necessary for an error to occur

What should happen when the form is empty and the Login button is pressed? Currently, the page opens without any errors. However, I want to display an error message under such circumstances. How can I modify the function to achieve this? const login = (e ...

Add a unique identifier to a table row in a jQuery/AJAX function without the need for a looping structure

My PHP query retrieves client data and generates a table with rows for each client. Each row contains a link with a unique ID attached to it. Clicking on this link triggers an AJAX function based on the client's ID, which opens a modal displaying info ...

Change the dropdown header behavior from hovering over it to clicking on it

This snippet of code is integrated into our header to showcase the cart. Currently, the dropdown appears when hovering over it. Is there a way to adjust this so that the dropdown shows up when onclick? <a href="#header-cart" class="skip-link skip-cart ...

What could be causing my update function to not run when I refresh the page?

As a non-developer trying to learn react.js, I am working on a section of my website that needs to update every few seconds with new content like a photo, header, and body text. I've encountered an issue where the data refreshes correctly after the p ...

unable to connect css file to document

My index.html file is not reading the style.css file for some reason, even though it is linked. I have added the type and checked the path, but still facing issues. Can anyone help troubleshoot this problem? Thank you. <!DOCTYPE html> <html lang ...

What is the best way to apply a conditional binding with v-model in Vue.js?

When working with JavaScript, you can utilize object spreading to include optional values like shown below: const payload = { name: "Joseph", ...(isMember && { credential: true }) }; In React, passing props optionally in JSX is as simple as this: &l ...

I could not retrieve data from the Promise {} object

Currently, I am in the midst of developing a discord bot using discord.js. When attempting to retrieve the target user, I utilize the following code: let target = message.guild.members.fetch(id). This method yields either Promise { <pending> } if the ...

Utilizing Next.js on Vercel with Sentry and opting out of source maps in the production environment

Currently setting up a Next.js application on Vercel with Sentry configuration thanks to the @sentry/next.js module. You can find an example repo here - https://github.com/voronianski/test-next-sentry-app This setup is based on the official example from N ...