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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:58:55+00:00 2026-06-15T11:58:55+00:00

I’m getting a mind-boggling response from jQuery that I’m hoping someone can help me

  • 0

I’m getting a mind-boggling response from jQuery that I’m hoping someone can help me with. I have a simple problem … I’m setting the “value” of a HTML form’s hidden field (aka, <input type='hidden'> when the form loads. I have a form with three hidden fields and two are working just fine. The third … well here’s the problem:

Once the form has completed loading (and yes it has loaded and is visible … as indirect proof the previous two hidden fields have loaded and successfully been set by jQuery), I run the following code (just showing relevant snippet as this final field is a date set to “today”):

case "today":
    SetFieldValue (targetElement , Date.today().toString("yyyy-MM-dd HH:mm:ss") );
    console.log ('Setting ' + jQuery(targetElement).attr('id') + ' to "today": ' + Date.today().toString("yyyy-MM-dd HH:mm:ss") );
    break;

The SetFieldValue is a little function I wrote to allow setting DOM elements regardless of what type it was. The code is follows:

function SetFieldValue ( domObject, value ) {
  // as a safety function, check if a string representation of the domObject was passed in and convert it to a jQuery object if it was
  if ( jQuery.type(domObject) === "string") {
    domObject = jQuery(domObject);
  }

  if ( jQuery.inArray (domObject.prop('tagName').toLowerCase(),['input' , 'select' , 'textarea']) >= 0 ) {
    console.log ("setting to value attribute: " + value);
    domObject.attr('value',value);
    console.log ("now set to: " + domObject.attr('value') + "(" + domObject.attr('id') + ")" );
  } else {
    console.log ("setting to html attribute");
    domObject.html( value );
  }
  return domObject;
}

Please note the console.log messages as this is important in understanding the craziness of the problem. When I run this, here’s what I get on the console:

enter image description here

Now I set a breakpoint at the last line of the “today” case statement (aka, on the “break;” line). Based on the console messages all is well. It appears the DOM element #activity-start_time has been set. Well here’s where it gets weird.

The first thing I do is test the reference to “targetElement” and the first thing the debugger console give me is an empty array:

empty set

What? That’s pretty odd. While I’m pondering that a few seconds pass and all of sudden it resolves itself to what I’d expect (I don’t retype it into the console it simply changes from the empty set to what you see below):

and now for something completely different

Now that the targetElement is exactly as I’d expect I do a simple check with jQuery that the DOM element of #activity-start_time is reporting the same value. You can see the result above. It’s precisely the same as targetElement except it HAS NOT got a value. What?!?

I’m at a complete loss. Any help would be greatly appreciated.

Ken

p.s. I will note that other people have suggested using .prop instead of .attr both seem to behave precisely the same.

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

    I know I didn’t provide enough context for people to really dig into this problem but I have in the end solved it. What was the issue? It was silly really … isn’t always? Anyway it was just a case of the DOM element in questions ‘id’ not beging unique. Grrr. It’s always the obvious things that you then go onto overlook that get you in trouble.

    Anyway, thanks for your patience and help.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.