I would like for a user to click an image in this table which is created dynamically based on the JSON data sent from the web service, and have the image change. When clicking the image again it will change back to the first image (inter-changing between only two images).
I have a table being created via jQuery's $.ajax() function which looks like this:
<table border="0" width=80% id="table">
<thead>
<tr>
<td><h3>Check to Renew</h3></td>
<td width=40%><h3>Vendor Part</h3></td>
<td width=100%><h3>Part Description</h3></td>
<td><h3>Unit Price</h3></td>
<td><h3>Quantity</h3></td>
</tr>
</thead>
<tbody>
<tr class="template">
<td><img src="images/checkmark.png" alt="check" id="row1" onclick=""></td>
<td>$vendorPart</td>
<td>$partDescription</td>
<td>$price</td>
<td><input class="quantityClass" name="quantity" value="$quantity"/></td>
</tr>
</tbody>
</table>
Here is the simple Javascript function which changes the images:
renewimg=Array("images/checkmark.png","images/gray_x.png");
function rowImageRefresh(y)
{
document.getElementById(y).src=renewimg[++m];
if (m==1)
{m=-1;}
}
This Javascript function work's beautifully, however only if I pass it the images id (in this case specific to the row). Hard coding for testing purposes proved this. My issue is I would like to be able to create a row id on the fly as the table row is created and then have functionality where that id can be passed.
I guess if I were to illustrate this more it would look something like this:
JavaScript: var row = 1;
HTML:
//table data
<td><img src="images/checkmark.png" alt="check" id="row+[i];i++;" onclick="rowImageRefresh(this.row.id)"></td>
//more table data
Where the id is created dynamically on the fly as each row is created and the onclick function passes the row of the image clicked.