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

  • Home
  • SEARCH
  • 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 8342295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:43:38+00:00 2026-06-09T05:43:38+00:00

I am coding to make simple validator for form. In order to validate form

  • 0

I am coding to make simple validator for form.

In order to validate form dynamically, I’ve planned to use eval function.

As you see in the javascript coding, var funcCall becomes a name of function with a parameter of jquery selected dom.

But that makes error. (Uncaught SyntaxError: Unexpected identifier)

What I’d like to know is that should I only use String in eval() or is there a better way to do this?


var Submit = {
    validateFilters : ["Submit.emptyCheckFilter"], // This is validator filters
    emptyCheckFilter : function(element) 
        //this is filter to validate if it's empty or not.
        console.log("this has been called");
    },
    doValidate : function(form) {
        var children = $(form).children();
        var filters = Submit.validateFilters;

        $.each(children, function(key, value) { // Loop over form element

            for(var i = 0; i < filters.length; i++) {
                //Here's error comes the value is not String. it's selected item by jQuery.
                //Uncaught SyntaxError: Unexpected identifier <= This occurs.
                var funcCall = filters[i] + "(" + value + ");";

                // Call the filter
                eval(funcCall);
            }

            return false; 
        });
    },
   ...
}
  • 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-09T05:43:40+00:00Added an answer on June 9, 2026 at 5:43 am

    You should not use eval for this. It is much simpler and cleaner to just use function instances directly instead of their “names”.

    var Submit = {
        validateFilters : [function(element) {
            //this is filter to validate if it's empty or not.
            console.log("this has been called");
        }], // This is validator filters
        doValidate : function(form) {
            var children = $(form).children();
            var filters = Submit.validateFilters;
    
            $.each(children, function(key, value) { // Loop over form element
    
                for(var i = 0; i < filters.length; i++) {
                    filters[i](value);
                }
    
                return false; 
            });
        },
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm coding a simple calculator and I want to make an unique function for
I'm trying to make a simple contact form for my website, so I bought
I am trying to use LWP::Simple to make a GET request to a REST
I'm coding simple game which I plan to make multiplayer (over the network) as
Which is the strictest mode of XHTML to make my coding habits semantically and
I have the below coding, i am make sure that if condition is TRUE,
Coming from the MS SQL world, I tend to make heavy use of stored
Trying to make a call and retrieve a very simple, one line, JSON file.
Doctrine 2 integration into ZF seems to make simple things very hard and time
I was able to make a simple webpart by following what was on this

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.