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

The Archive Base Latest Questions

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

I have created a form in a modal box with a table. When you

  • 0

I have created a form in a modal box with a table. When you click on a table row it populates a form on the parent page. This is working great but I can’t get the values to change when I click on another table row. Because I’m using IDs it only takes the values from the first table row. I am open to changing to classes but I tried this and it didn’t help.

Please can anyone help me with this. The code is below.

Modal Form with Table

<div id="modal_form" title="Address Search">
<form id="modal_form">
<ul>
    <li><label for="name">Search by street description</label>
        <input type="text" name="street_description" id="street_description" />
        <input type="button" id="search_button" class="form_button" value="Search"></li>
</ul>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="table-data">
              <tbody><tr>
                <td width="200px"><a href="#">Street</a></td>
                <td width="200px"><a href="#">Suburb</a></td>
                <td width="200px"><a href="#">City</a></td>
              </tr>
              <tr>
                <td id="address_street">Harambee Road</td>
                <td id="address_suburb">Onerai </td>
                <td id="address_city">Onerai Rural</td>
              </tr>
              <tr>
                <td id="address_street">Hutchinson Road</td>
                <td id="address_suburb">Onerai </td>
                <td id="address_city">Onerai Rural</td>
              </tr>
              <tr>
                <td id="address_street">Kauri Road</td>
                <td id="address_suburb">Onerai </td>
                <td id="address_city">Onerai Rural</td>
              </tr>
        </tbody></table><!-- /table#table-data -->
</form>

Javascript (This is where I need to differentiate between the table rows)

<script type="text/javascript">
$(document).ready(function() {
$('#table-data tr').click(function () {
$('#street_name').val( $('#address_street').text() )
$('#suburb').val( $('#address_suburb').text() )
$('#city').val( $('#address_city').text() )})
});
</script>

Parent Form, where the form fields are populated

<form id="profile">
<ul>
<li><label for="street_number">Street Number</label><input id="street_number" type="text" placeholder="Street Number" name="street_number" ><input type="button" class="form_button" id="find_address" value="Find Address"></li>
<li><label for="street_name">Street Name</label><input id="street_name" type="text" placeholder="Street Name" name="street_name"  disabled="disabled" ></li>
<li><label for="suburb">Suburb</label><input id="suburb" type="text" placeholder="Suburb" name="suburb"  disabled="disabled" ></li>
<li><label for="city">City</label><input id="city" type="text" placeholder="City" name="city" disabled="disabled" ></li>
<li><input type="submit" id="submit" value="Save"></li>
</ul>
</form>

Thanks for any help you can give, cheers

  • 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-24T17:15:44+00:00Added an answer on May 24, 2026 at 5:15 pm

    IDs must be unique, so this is not going to work:

    <td id="address_street">Harambee Road</td>
    ...
    <td id="address_street">Hutchinson Road</td>
    

    I would give each of the rows an ID, and have all of the columns use the same class:

    <tr id="row1">
      <td class="address_street">Harambee Road</td>
      <td class="address_suburb">Onerai </td>
      <td class="address_city">Onerai Rural</td>
    </tr>
    <tr id="row2">
      <td class="address_street">Hutchinson Road</td>
      <td class="address_suburb">Onerai </td>
      <td class="address_city">Onerai Rural</td>
    </tr>
    <tr id="row3">
      <td class="address_street">Kauri Road</td>
      <td class="address_suburb">Onerai </td>
      <td class="address_city">Onerai Rural</td>
    </tr>
    

    Your JavaScript would change to be like this:

    <script type="text/javascript">
      $(document).ready(function() {
        $('#table-data tr').click(function () {
          var curRowId = $(this).attr("id");
          $('#street_name').val( $('#' + curRowId + ' td.address_street').text() );
          $('#suburb').val( $('#' + curRowId + ' td.address_suburb').text() );
          $('#city').val( $('#' + curRowId + ' td.address_city').text() );
        });
      });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a form in a modal box with a table. When you click
I have created an form validation using ajax/php. Each text box is validated using
I have created a great stand-alone web form in asp.net utilizing many jQuery features
I would like to have a non-modal alert box called form a batch file.
if i have created a view model and have a partial form that is
I have created a form that is used for both adding and editing a
I have created a non-form c# program that uses the NotifyIcon class. The text
I want to globalize my application. I have created a small form which asks
I am using ASP.NET2.0. I have created a download form with some input fields
I am a bit confused. I have created a simple form with a one

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.