Table Populating Input fields on click
by Joe Saad
HTML
<!--
form[action="http://www.reliant.com"]>table>(thead>tr>(th{Address}+th{Zipcode}+th{Distance}+th{action}))+tbody>tr*10>td{Address $}+td{7700$}+td{$}+td>a[href="#"]{View}
form[action="http://www.reliant.com"]>table(>(thead>tr>(th{Address}+th{Zipcode}+th{Distance}+th{action}))+tbody>tr*10>td{Address $}+td{7700$}+td{$}+td>a[href="#"]{View})+input[type="text"][name="address"]+input[type="text"][name="zipcode"]
-->
<form action="http://www.reliant.com">
<table>
<thead>
<tr>
<th>Address</th>
<th>Zipcode</th>
<th>Distance</th>
<th>action</th>
</tr>
</thead>
<tbody>
<tr>
<td>Address 1</td>
<td>77001</td>
<td>1</td>
<td><a href="#">View</a></td>
</tr>
<tr>
<td>Address 2</td>
<td>77002</td>
<td>2</td>
<td><a href="#">View</a></td>
</tr>
<tr>
<td>Address 3</td>
<td>77003</td>
<td>3</td>
<td><a href="#">View</a></td>
</tr>
<tr>
<td>Address 4</td>
<td>77004</td>
<td>4</td>
<td><a href="#">View</a></td>
</tr>
<tr>
<td>Address 5</td>
<td>77005</td>
<td>5</td>
<td><a href="#">View</a></td>
</tr>
<tr>
<td>Address 6</td>
<td>77006</td>
<td>6</td>
<td><a href="#">View</a></td>
</tr>
<tr>
<td>Address 7</td>
<td>77007</td>
<td>7</td>
<td><a href="#">View</a></td>
</tr>
<tr>
<td>Address 8</td>
<td>77008</td>
...
JavaScript
$('a').click(function(){
var myAddress = $(this).closest('tr').find('td:first-child').text(),
myZipcode = $(this).closest('tr').find('td:nth-child(2)').text();
$('input[name="address"]').val(myAddress);
$('input[name="zipcode"]').val(myZipcode);
});