<table id="ratecardlist">
<tr>
<th> Show Time</th>
<th> Balcony </th>
<th> Box </th>
<th> </th>
</tr>
<tr>
<td>10.30AM</td>
<td><input type="text" name="bal:1:3" value="100" /> </td>
<td><input type="text" name="box:1:5" value="200" /> </td>
<td><a href="#" onClick="applytoAll();">Apply To All</a></td>
</tr>
<tr>
<td>1.30PM</td>
<td><input type="text" name="bal:3:3" value="400" /> </td>
<td><input type="text" name="box:3:5" value="450"/> </td>
<td> </td>
</tr>
<tr>
<td>6.30PM</td>
<td><input type="text" name="bal:5:3" value="600" /> </td>
<td><input type="text" name="box:5:5" value="600" /> </td>
<td> </td>
</tr>
.
.
.
</table>
Apply to All link will always in second row. When I Click Apply To All, input values in this row should copy to other rows input fields. How to do that plz Help.
e.g.
After click Apply To All,
<table id="ratecardlist">
<tr>
<th> Show Time</th>
<th> Balcony </th>
<th> Box </th>
</tr>
<tr>
<td>10.30AM</td>
<td><input type="text" name="bal:1:3" value="100" /> </td>
<td><input type="text" name="box:1:5" value="200" /> </td>
<td><a href="#" onClick="applytoAll();">Apply To All</a></td>
</tr>
<tr>
<td>1.30PM</td>
<td><input type="text" name="bal:3:3" value="100" /> </td>
<td><input type="text" name="box:3:5" value="200"/> </td>
<td> </td>
</tr>
<tr>
<td>6.30PM</td>
<td><input type="text" name="bal:5:3" value="100" /> </td>
<td><input type="text" name="box:5:5" value="200" /> </td>
<td> </td>
</tr>
.
.
.
</table>
First, the way you’re handling the
clickevent does not provide enough context (e.g. the clicked element) to the handler. Ideally, you would decorate your link with anidor aclassattribute and use that to register the handler unobtrusively (through jQuery’s click() method, for instance).If you’re stuck with your current strategy, you should at least pass the clicked element to the handler:
From there, you can implement the function as follows:
This solution supports an arbitrary number of input elements per row, not just two.