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

  • Home
  • SEARCH
  • 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 8944969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:08:27+00:00 2026-06-15T12:08:27+00:00

I have a function which passes in a jQuery object called targetElement which is

  • 0

I have a function which passes in a jQuery object called “targetElement” which is the form field that I need to operate on. I use this function to set default values for a form after it loads. In one form I have three hidden form elements (aka, <input type="hidden">) each one is assigned a value and two of the three work fine. The third is driving me nuts.

Here’s a code snippet within the function:

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;

Where the SetFieldValue function is:

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;
}

Here’s the thing. I set a debug breakpoint directly after the call to SetFieldValue. I typed “targetElement” which clearly shows that the value HAS been set. Yet, when I type a jQuery reference to the DOM field it shows up without the value set. Huh?

enter image description here

Now there is one thing I didn’t mention … and I suspect it’s important … when I typed “targetObject” into the debugger the first thing it did was return an empty array:

enter image description here

Then a second or two later it expanded auto-magically into the screen shot you saw initially. Please help!

UPDATE

I really appreciate all the help so far but I suspect the real problem is hinted at by the “delay” in response to targetElement (a jQuery object). See above for more details. I have also added another interesting snapshot below. If you notice the log.console statements in the code this will make sense:

enter image description here

What I have attempted to do is:

a) state what I’m going to set the value to
b) set the value to stated intention (aka, 2012-12-02 00:00:00)
c) check that it has been set (it has)
d) then check again from the calling routing (this also confirms it has been set)

On the line immediately following the last log.console (the “break” statement) I put a breakpoint and the debugger no disagrees with all the console messages. Bizzarre!

UPDATE 2

People have asked for additional context, well “code” to be precise. I am struggling to figure out a good way to give a compact module of code that will reproduce the problem so I thought maybe a short screencast demonstrating the problem would help. Here’s two attempts at that:

screencast 1
screencast 2

  • 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-15T12:08:28+00:00Added an answer on June 15, 2026 at 12:08 pm

    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 it 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 JS function which is passed a string that a RegEx is
hi i have function which is called by tinker listbox so i cannot return
Can I´m asking for advice. I have function which should return javascript object function
I have a function which looks something like this, it returns a noncopyable class
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation
I have a html textbox on which I've bound a function via jQuery to
I have a controller action which is getting called by JQuery ajax, and hopefully
I have form which contains more (dynamic) wrap-segments, I am trying to create object
The wierdest thing. I have a function which calls: var clicked_el = event.target.id; This
i have an input field which calls the function inputInlineHint(self) on blur and on

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.