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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:35:59+00:00 2026-05-27T20:35:59+00:00

I have a table of assignments. Within each row is a cell, that when

  • 0

I have a table of assignments. Within each row is a cell, that when clicked will bring up a hidden div to the right of the table. Within the div is a form that allows a user to associate a selected document with a task.

Currently the table is generated, in part, by a PHP “for” loop; I am cycling through an array and creating a new table row for each array index.

Within each row there are two table cells. I want the contents of one of the cells to be a hyperlink that, when clicked, will display a hidden div. Within the hidden div will be a form. The form will have a hidden input box, and I would like to dynamically set this value when the hyperlink is clicked.

Here is a sample of the table:

<table>
  <tr>
    <th>Task</th>
    <th></th>
  </tr>

  <?php
    for($i=0; $i<sizeof($task_array); $i++)
    { ?>
      <tr>
         <td><?php echo $task_array[$i]['task'];?></td>
         <td><a href="#" id="show_div">Attach Doc</a></td>
      </tr>
    }
  ?>
</table>

Here is the hidden div and form:

<div id="hidden_div">
  <form action="[url]" method="post" enctype="multipart/form-data">
  <label for="file">Filename:</label>
  <input type="file" name="file" id="file" />           
  <input type="hidden" id="task_id" value="">
  <input type="submit" name="submit" value="Submit" />
  </form>
</div>

I know that I can do the following with JQuery to display the hidden div:

$("#hiddendiv").show();

I also know that the hidden field ‘task_id’ can be set with JQuery by using

$("#task_id").val() = 'some value';

The problem I am having is that, since the values are coming from an array, I’m not sure how to specify a specific value. For example, the value of a task id is found in the variable $task_array[$i][‘task_id’]. I could try this:

$('#show_div').click(function(){
     $("#hiddendiv").show();
             $("#task_id").val() = ???
});

I’m sort of stuck on specifying for which iteration to use the task id value.

My apologies if that wasn’t very clear. Any help would be appreciated. Thanks.

  • 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-27T20:36:00+00:00Added an answer on May 27, 2026 at 8:36 pm

    PHP

      <?php
        for($i=0; $i<sizeof($task_array); $i++)
        { ?>
          <tr data-task-id="<?php echo $task_array[$i]['task_id'];?>">
             <td><?php echo $task_array[$i]['task'];?></td>
             <td><a href="#" id="show_div">Attach Doc</a></td>
          </tr>
        }
      ?>
    

    See that I added a data-attribute named data-task-id to the tr elements that stores the task_id for that row. We can use this in a click event handler later.

    JS

    //bind an event handler to the `tr` elements for the `click` event to show the `tr`s children elements (the `td`s)
    $('tr').on('click', function () {
        $(this).children().show();
    
        //this next line is how we get the `task_id` associated with a row
        $(this).attr('data-task-id');
    });
    
    //since we bound an event handler to the `tr` elements for the `click` event it's a good idea to stop the propagation of click events on links within the `tr` elements so the event doesn't bubble up the the `tr` elements
    $('tr').find('a').on('click', function (event) {
        event.stopPropagation();
    });
    

    Note that .on() is new in jQuery 1.7 and in this case is the same as .bind().

    Also, you need to change the #show_div element’s ID for each element (IDs must be unique). I recommend just changing it to a class instead of using an id:

    <td><a href="#" class="show_div">Attach Doc</a></td>
    

    Then you can bind an event handler to it like this:

    $('.show_div').click(function(){
         $("#hiddendiv").show();
         $("#task_id").val($(this).parents('tr').eq(0).attr('data-task-id'));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that stores all the volunteers, and each volunteer will be
I have table A in Oracle that has a primary key (id). I need
I have table that I insert data with following query (from c# code): INSERT
Suppose that we have the following partial ER diagram: Notice that the attachments table
In my scheduling database, I have an assignments table with the following fields: |
I have a table of user group assignments, such as: ID----UserName------Group 01 johnsmith admin
i want to display an image besides the text in table cell. i have
I have a ListView that I set it's ItemsSource to list all the Assignments
So I have a table that has, employee number, employee name, supervisor number. I
I have an old table with a few rows that has a datetime column.

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.