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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:35:19+00:00 2026-06-18T02:35:19+00:00

I want to load a cookie value directly to all html field with an

  • 0

I want to load a cookie value directly to all html field with an specific class when the page is loaded. I have a cookie created with the same name as the field’s id.

Doing this does not work.

$(".class").val(function(){
    el=$(this);
    id=el.attr("id");
    cookie_val=$.cookie(id);
    el.val(cookie_val);
});

Any idea?

  • 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-18T02:35:20+00:00Added an answer on June 18, 2026 at 2:35 am

    When passing a function to jQuery’s .val() method, the desired value should be returned by the function.

    As your code stands, your function is being run which does set the value. It then returns undefined, however, which sets it to empty.

    This should work:

    $('.class').val(function () {
        return $.cookie($(this).attr('id'));
    });
    

    Alternatively, you could use .each() to have your function do the value setting without needing to return:

    $('.class').each(function () {
        var el = $(this);
        el.val($.cookie(el.attr('id')));
    });
    

    FWIW, I wrote a cookies library which provides jQuery plugins for this very functionality (fill a field with the value held by a cookie of the same name).

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

Sidebar

Related Questions

I want to load a palette from a bitmap file I have created. The
I have a html page with multiple javascript tags. The problem that I want
I want to load up a random image while a page it is loading
I want to load defined folders into my website from same system, now I
I have created an application using c# SDK. The canvas page http://mywebsite/ is working
I want to reduce load times on my websites by moving all cookies into
Say I have a website called a.com , and when a specific page of
I have created a simple shopping cart application. We needed something specific to our
I have a page that sets a cookie and then redirects the user to
I want to be able to set the value of a hidden field to

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.