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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:30:20+00:00 2026-05-26T04:30:20+00:00

I have a ajax form that populates select lists with values based on the

  • 0

I have a ajax form that populates select lists with values based on the previous selected select list item. This form is used in 3 different views with each view adding an extra select list. I have written some basic validation code that keeps the form process in sync and doesn’t confuse the user.

I have written one function that handles all 3 forms in an external script file.

My Question:
Is it acceptable or is there anything I need to worry about if some of my variables are undefined based on the form and view?

Here is some sample code that illustrates my question:
Note: These are not the actual names of my variables.

    (function ($){
    var objects = {sl1:$('#SelectList1'),sl2:$('#SelectList2'),sl3:$('#SelectList3'),lbl1:$('#Label1'),lbl2:$('#Label2'),lbl3:$('#Label3')};
    objects.sl1.change(function(){
    mapValues();
    }
    function mapValues(){
    objects.lbl1.text(objects.sl1.val());
    objects.lbl2.text(objects.sl2.val());
    objects.lbl3.text(objects.sl3.val());//What if this select list is undefined for View1?
}
    })(jQuery);

To summarize, View #1 has SelectList1 & SelectList2. View #2 has all 3. Is there a performance issue or is it bad practice to call a function where some of the variables are undefined?

Thanks.

  • 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-05-26T04:30:21+00:00Added an answer on May 26, 2026 at 4:30 am

    This is more of a jQuery issue, not a JS one. jQuery simply does nothing (it does not even fail!) if you execute a method such as .text() or .val() on an empty result from a selector. For the performance issue, test it yourself. If the element is not found, I expect the performance to be a little better compared to when an element exists.

    So, it’s valid to use such code.

    Note that you’re mixing up “undefined variables” with “non-available elements” which are totally different matters. Using undefined variables is strongly discouraged and often lead to unexpected behavior.

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

Sidebar

Related Questions

I have a form containing a list of input fields that the user populates
I have an Ajax form that updates a div when submitted with a submit
I have an Ajax contact form that links to a jquery file but for
I have some AJAX work that brings across an additional form element that I
I have a form that uses jQuery to submit an ajax post and it
I have a form that I'm submitting with AJAX. A user fills out the
I have a contact us form that uses Ajax (i.e. relies on asynchronous requests).
I currently have a PHP form that uses AJAX to connect to MySQL and
In my application I have a drop-down form that fires up an AJAX request
I have a small jQuery plugin that I use for form AJAX validation. There

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.