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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:07:35+00:00 2026-06-11T11:07:35+00:00

How to declare variables this way: var sarr = $(#crop_vals).find(input); $(sarr).each(function() { var $(this).attr(id)

  • 0

How to declare variables this way:

var sarr = $("#crop_vals").find("input");
$(sarr).each(function() { 
    var $(this).attr("id") = $(this).val();
});

What I want is to have var named the id equivalent to the value.

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

    To set the “variables” globally (though you shouldn’t do this because it’s asking for trouble)

    var sarr = $("#crop_vals").find("input");
    $(sarr).each(function() { 
        window[ this.id ] = this.value;
    });
    

    To set them in a safer way, you could do

    var sarr = $("#crop_vals").find("input"),
        myVars = {};
    $(sarr).each(function() { 
        myVars[ this.id ] = this.value;
    });
    

    and access with myVars[ id ].

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

Sidebar

Related Questions

I want to declare multiple variables in a function: function foo() { var src_arr
I have declared this variable in jquery var enabled = false; I want to
In Javascript, if I declare variables with var in javascript outside of a function
In the SQL Server, I can define local variables like this. declare @id number
I want to declare static(or not static) variable inside Enum. I need this because
I have a variable declared at the top of my function as this.current_test =
Long story short: var o="before"; x = function() //this needs to be an anonymous
I have an Array with this kind of values: val = [ ['L-2-4-1','john','bla1'], ['L-1-1-26','bohn','bla2'],
I have some javascript code (within an object) : toggle: function() { var me
Backbone.js documentation suggest loading bootstrapped models this way: <script> var Accounts = new Backbone.Collection;

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.