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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:56:15+00:00 2026-05-20T17:56:15+00:00

In an attempt to create cleaner code, I am trying to write event handler

  • 0

In an attempt to create cleaner code, I am trying to write event handler functions that are aware of where they get called from. I am not sure if what I’m trying to do is not the correct way to do things, or if the underlying nesting of divs within tables that the page is made up of is causing problems.

The goal of the below table/js is to take data from the attributes of the image tag, and populate them into the input elements within the parent/ancestor table.

Table Structure:

<table id="formbody">

    <tr><td>
    <table class="form_item_wrapper" id="form_item_1">

        <tr><td><div id="search_results"><img class="event_handler" foo="bar" /></div></td></tr>

    <tr><td>Foo: <input id="event_input" name="foo_input_1"></td></tr>
   </table>

    <table class="form_item_wrapper" id="form_item_1">
        <tr><td>
            <div id="search_results"><img class="event_handler" foo="baz" /></div>
        </td></tr>

     <tr><td>Foo: <input id="event_input" name="foo_input2"></td></tr>
    </table>

     </td></tr>


</table>

Each of the .form_item_wrapper tables has a section that can dynamically populate the list of .event_handler images. Once the $.get() that retrieves the entries populates the data, it attaches the handlers to the images to fire populate_shipment_details(event) onclick. That part works fine, the events fire correctly and I can read my custom attributes from the image elements. This is the function that gets called when one of the images is clicked:

function populate_shipment_details(event){

var form_wrapper = $(event.target).closest('.form_item_wrapper');

var foo_input = $(form_wrapper).children('#event_input');

    foo_input.val($(event.target).attr('foo'));

}

The problem I am having is that while form_wrapper properly resolves to the table containing the image that was clicked on, Firebug is showing that foo_input is showing up “emtpy” in Firebug. For whatever reason, I cannot create variables that point to children within the form_wrapper. Ideally, this is the code that I want to write… but doesn’t work.

$(form_wrapper).children("#event_input").val($(event.target).attr('foo'));
  • 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-05-20T17:56:15+00:00Added an answer on May 20, 2026 at 5:56 pm

    Here you go:

    $('img.event_handler').click(function() {
        $(this).closest('tr').next().find('input.event_input').val($(this).attr('foo'));
    });
    

    Live demo: http://jsfiddle.net/simevidas/HMJcy/

    Note: I had to replace the id attribute with the class attribute on the INPUT elements, since ID’s have to be unique on the page, and you have multiple INPUT’s.

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

Sidebar

Related Questions

I’m trying to create a Files task item group with a metadata attribute called
I'm trying to create a lookup column that would return the index of the
My attempts to query MySQL from PHP with a create statement of a store
Has there been any attempt and creating a formalized method for organizing CSS code?
I'm after a simple stored procedure to drop tables. Here's my first attempt: CREATE
I have a console application from which I create a window. I can render
I want to dynamically change the address of a WCF service called from my
I had an issue with mocking Apache Http client. The following attempt to create
I've created the following regex pattern in an attempt to match a string 6
If I attempt to connect to Mac OS X 10.5 Leopard's built in vnc

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.