I am really confused about how I can do this. I need to get the value of two <td> when one is selected. For example, below let’s say I select the td with id=monthly of $550 dollars. I need to get the age and excess that corresponds with that price. I hope this makes sense. SO in the example of selecting $550 I need jQuery to get the values age(18-24) and excess($1000). I then will take these two values and insert into mysql as noted below. Is there anyway I can do this with either jQuery or PHP? I am open to ideas.
<table>
<tr>
<td width="67"></td>
<td width="102" id="excess">$1000</td>
<td width="102" id="excess">$2000</td>
</tr>
<tr>
<td width="67" id="age">18-24</td>
<td width="102" id="monthly">$550</td>
<td width="102" id="monthly">$650</td>
</tr>
<tr>
<td width="67" id="age">25-29</td>
<td width="102" id="monthly">$750</td>
<td width="102" id="monthly">$850</td>
</tr>
</table>
MYSQL(using the example above):
$query = mysql_query("UPDATE table SET Monthly = '$550' WHERE Age = '18-24' AND Excess = '$1000'")or die(mysql_error());
Your HTML is invalid. You cannot have more than one element with the same
id,idvalues (as the name suggests) must be unique. If you’re trying to classify elements, use aclass. The rest of this answer assumes thoseidvalues have been changed toclassnames.If I understand you, you want to handle clicks on cells with the
monthlyclass and get the text of the first cell in the row along with the first cell in the column. This is easily done with jQuery (live example | source):We find the first cell in the row by finding the row via
closest, then finding its first cell viafindandfirst.We find the first cell in the column by finding the table via
closest, then getting the first row viafindandfirst, then getting theindexof the clicked cell and finding the cell in the first row with the same index viaeq.