Click here to Skip to main content
15,886,038 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Team

I am using jquery messaging and they do not work as expected. Meaning when a user before insert any value from the contact form. it must check it has all the required fields. Currently from the front end it does that but there are no messaging display and when i inspect the element from the browser, i get the following error "
Uncaught SyntaxError: Cannot use import statement outside a module (at messages.min.js:1:437)
".

What I have tried:

JavaScript
<pre lang="Javascript">
<script src="js/jquery.validate.js"></script>
    <script src="js/signup-form.js"></script>
    <script src="js/messages.min.js"></script>



// signup-form messaging
/**
@author:Gcobani Mkontwana
@date:10/02/2023
signup-form.js
*/

$().ready(function() {
    
$('#signup-form').validate({
rules:{
    name: {
        required:true,
        minlength:12
    },
    surname:{
        required:true,
        minlength:15
    },
    email:{
        required:true,
        email:true
    },
    confirmed_email:{
        required:true,
        confirmed_email:true
        
    },
    phone_number: {
        required:true,
        phone_number:true,
        minlength:10
    },
    service_number:{
        required:true,
        service_number:true,
        minlength:10
    },
    agree: {
        required:true,
        agree:true
    }
},
messages: {
    name: {
        required:"Please enter your name",
        minlength:"Your name must have at least 12 characters"
    },
    surname: {
        required:"Please enter your surname",
        minlength:"Your surname must have at least 15 characters"
    },
    email: {
        required:"Please enter your email address",
        equalTo:"Please enter the same email address as above"
    },
    agree: "Please accept our policy"
}

})
});
Posted
Updated 22-Feb-23 4:05am

1 solution

One of your script files is designed to be used as a Javascript module:
JavaScript modules - JavaScript | MDN[^]

But you are loading it as a regular script, which will not work.

There's no sign of an import statement in the script block you've posted, so it must be one of the other files. Unfortunately, we don't have access to your copy of those files, so we can't tell you which.
 
Share this answer
 
Comments
Gcobani Mkontwana 22-Feb-23 18:00pm    
@Richard Deeming, what i tried was this on using an old version of jquery messaging. On the javascript tag i tried to use How do i pass this problem?
Richard Deeming 23-Feb-23 3:48am    
Check the scripts you're loading to make sure they're regular scripts, and not modules. An import statement at the top of the file means it's a module.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900