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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:09:38+00:00 2026-06-16T20:09:38+00:00

I have stared too long on this apparently not working little piece of code.

  • 0

I have stared too long on this apparently not working little piece of code. Why doesn’t select box rel attribute get alerted?

HTML:

<select rel="prop216" name="prop[]">
  <option value="">- none</option>
  <option value="12">Opt 1</option>
  <option value="13">Opt 2</option>
</select>
<select rel="prop217" name="prop[]">
  <option value="">- none</option>
  <option value="12">Opt 1</option>
  <option value="13">Opt 2</option>
</select>

jQuery:

$("select").change(function()
{
 var i = 0;
 var alteredSelects = [];
 $("select").each(function()
 {
    if ( $(this).val() !== "" )
    {
        alteredSelects[i][0] = $(this).attr('rel');
        alteredSelects[i][1] = $(this).val();
        alert ($(this).attr('rel'));
        i++;

    }
 });
});

See also my jSfiddle: http://jsfiddle.net/ft6Bd/1/

I get an error in Firefox

TypeError: can’t convert undefined to object

on the line alteredSelects[i][0] = $(this).attr('rel');

But can’t seem to realize why.

  • 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-16T20:09:40+00:00Added an answer on June 16, 2026 at 8:09 pm

    You first have to initialize alteredSelects[i] before you can assign values to it:

    $("select").change(function() {
        var i = 0;
        var alteredSelects = [];
        $("select").each(function() {
            if ( $(this).val() !== "" ) {
                alteredSelects[i] = []; // <-- Initialize `alteredSelects[i]` as empty array.
                alteredSelects[i][0] = $(this).attr('rel');
                alteredSelects[i][1] = $(this).val();
                alert($(this).attr('rel'));
                i++;
            }
        });
    });
    

    The problem was that you were trying to save something to alteredSelects[i], while alteredSelects[i] was null.

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

Sidebar

Related Questions

I have stared at this short code too long, and cannot for the life
I'm working on some code, and got stuck on this stored procedure problem... Have
Hi this is a simple question, however I have now stared at it long
I have been staring at this for too long and I can't seem to
Not too long ago I started writing a docking library for WPF (similar to
Started using PDO prepared statements not too long ago, and, as i understand, it
I am getting this error in my development environment. I have spent far too
Ok, I've been racking my brain on this one solo for too long. I've
I've been battling with this for too long so I'm here to ask for
I have a problem/question that I may have been staring at too long today.

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.