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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:20:06+00:00 2026-06-11T03:20:06+00:00

I have a snippet of javascript that I’m using to track form engagement. I

  • 0

I have a snippet of javascript that I’m using to track form engagement. I use $(this) to pass an object to two functions in my script but my next few lines of code aren’t executed because Chrome says “Cannot read property ‘length’ of undefined. Why can’t I use the $(this) reference anymore?

$('select').blur(function () {

                var input_category = get_input_category($(this));

                var form_identifier = get_form_identifier($(this));

                if($(this).attr('name').length) {
// This is where I get the error ^^
                    var object_identifier = $(this).attr('name');
                }
                else if($(this).attr('id').length) {
                    var object_identifier = $(this).attr('id');
                }
                else if($(this).attr('class').length) {
                    var object_identifier = $(this).attr('class');
                }
                else {
                    var object_identifier = null;
                }
});

Edit: The select box doesn’t have a name value attached.

                        <select type="select">
                          <option value="volvo">Volvo</option>
                          <option value="saab">Saab</option>
                          <option value="mercedes">Mercedes</option>
                          <option value="audi">Audi</option>
                        </select>

But isn’t that what my script looks for? If it doesn’t have a name, I want it to move on. How do I check for the attribute without getting an error?

  • 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-11T03:20:07+00:00Added an answer on June 11, 2026 at 3:20 am

    As was seen by Vega, the problem is on the attr('name') value.

    Don’t check the length of an object to check it’s defined, because this will raise an error when there is no object on which the length could be taken.

    Simply check it’s defined and has a non empty value using the usual js pattern :

    if ($(this).attr('name'))
    

    instead of

    if ($(this).attr('name').length)
    

    Note that the first test checks also this isn’t "". So there is absolutely no reason to check both that the object is defined and isn’t "".

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

Sidebar

Related Questions

Can you guys help me figure this out? I have the following JavaScript snippet:
I have a snippet of javascript that displays the amount of sessions available for
I cannot write Javascript but I have a snippet that I'm adding into a
I have the following Javascript snippet that receives an customerID via parameter (i'm going
I have this javascript snippet which passes an id and the reffering page to
I have a snippet of Javascript that I need to debug: var httpRequest =
I have a JavaScript snippet that runs very well on Firefox and Safari, but
I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
I have a snippet of javascript that is used to pull a series of
I have a javascript (jquery) snippet that is link to a href=# to toggle

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.