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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:22:01+00:00 2026-05-25T01:22:01+00:00

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

  • 0

I created a form in a modal box with a table. When you click on a table row it populates a postal address form on the parent page. Everything was going swimmingly (with the help of StackOverflow) but then I got the task of adding a second button for a street address.

I have added the second button and linked it to the same form, now I need a way to pass a variable so the first button only writes to the form fields I specify, and the same for the second button.

Any help will be appreciated.

The code – JS Fiddle example – http://jsfiddle.net/clintongreen/rc2Ky/

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.

Modal Box with table

<div id="modal_form" title="Address Search">
<form id="address_search">
<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 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">Mt Wellington</td>
                <td class="address_city">Auckland City</td>
              </tr>
              <tr id="row3">
                <td class="address_street">Kauri Road</td>
                <td class="address_suburb">Westfordshire</td>
                <td class="address_city">Palmerston North</td>
              </tr>
        </tbody></table><!-- /table#table-data -->
    </form>
</div><!-- /div#modal_form -->

Javascript

<!-- TO OPEN THE MODAL BOX -->
<script type="text/javascript">
$(document).ready(function() {
$('#find_address').click(function(){
$('#modal_form').dialog('open');
}); //end click handler
$('#find_address1').click(function(){
$('#modal_form').dialog('open');
}); //end click handler
}); //end ready event
</script>

<!-- FOR FIRST BUTTON -->
 <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() );
  $("#modal_form").dialog('close');
    });
  });
</script>

<!-- FOR SECOND BUTTON -->
<script type="text/javascript">
  $(document).ready(function() {
    $('#table-data tr').click(function () {
      var curRowId = $(this).attr("id");
      $('#street_name1').val( $('#' + curRowId + ' td.address_street').text() );
      $('#suburb1').val( $('#' + curRowId + ' td.address_suburb').text() );
      $('#city1').val( $('#' + curRowId + ' td.address_city').text() );
  $("#modal_form1").dialog('close');
    });
  });
</script>

Form where the fields are populated

 <form id="profile">
 <ul>
<!-- FIRST BUTTON SECTION -->
 <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>

<!-- SECOND BUTTON SECTION -->
 <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_address1" value="Find Address"></li>
 <li><label for="street_name1">Street Name</label><input id="street_name1" type="text" placeholder="Street Name" name="street_name1"  disabled="disabled" ></li>
 <li><label for="suburb1">Suburb</label><input id="suburb1" type="text" placeholder="Suburb" name="suburb1"  disabled="disabled" ></li>
 <li><label for="city1">City</label><input id="city1" type="text" placeholder="City" name="city1" disabled="disabled" ></li>

 <li><input type="submit" id="submit" value="Save"></li>
 </ul>
 </form>
  • 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-25T01:22:01+00:00Added an answer on May 25, 2026 at 1:22 am

    I managed to solve this by changing the classes of the td with the button click, I also had to change the class of the table. The code I used is below.

    The Code

    <script type="text/javascript">
    $(document).ready(function() {
    $('#find_address').click(function(){
    $('#modal_form').dialog('open');
    $('table#table-data_postal').attr( 'id', 'table-data' );
    $('td.address_street_postal').removeClass("address_street_postal").addClass("address_street");
    $('td.address_suburb_postal').removeClass("address_suburb_postal").addClass("address_suburb");
    $('td.address_city_postal').removeClass("address_city_postal").addClass("address_city");
    $('td.address_code_postal').removeClass("address_city_postal").addClass("address_code");
    $('label#suburb_search').css('display','none');
    $('label#street_search').css('display','inline');
    $('input#street_description').css('width','330px');
    }); //end click handler
    $('#find_address_postal').click(function(){
    $('#modal_form').dialog('open');
    $('table#table-data').attr( 'id', 'table-data_postal' );
    $('td.address_street').removeClass("address_street").addClass("address_street_postal");
    $('td.address_suburb').removeClass("address_suburb").addClass("address_suburb_postal");
    $('td.address_city').removeClass("address_city").addClass("address_city_postal");
    $('td.address_code').removeClass("address_code").addClass("address_code_postal");
    $('label#suburb_search').css('display','none');
    $('label#street_search').css('display','inline');
    $('input#street_description').css('width','330px');
    }); //end click handler
    }); //end ready event
    </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 with a dialog search box for a Street Address and
I created a form application with 1 button and 1 text box to see
I have created an form validation using ajax/php. Each text box is validated using
I'm making an edit button which pops up a modal box with a form
I would like to have a non-modal alert box called form a batch file.
I am going to create a form inside of a tabbed modal dialog (aka
if i have created a view model and have a partial form that is
I created a form with a label, textbox and a button. In the form
I created a form that overlays on top of another form in an alpha
I created a form using Swing in Java. In the form I have used

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.