Таблица
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<table width="444" border="1"><tr>
<td width="214" rowspan="2">
<div id="ctl00_MainContent_Info_ctl00_upd_small"> 16500 </div>
</td>
<td width="214">
<input name="ctl00$MainContent$Info$ctl00$Purchase1$txtPurchasePrice" type="text" maxlength="30" id="ctl00_MainContent_Info_ctl00_Purchase1_txtPurchasePrice" style="width:180px;text-align: center">
</td>
</tr>
<tr>
<td>
<input type="submit" name="ctl00$MainContent$Info$ctl00$Purchase1$btnMakePurchase" value="Купить" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$Info$ctl00$MakePurchase1$btnMakePurchase", "", true, "", "", false, false))" id="ctl00_MainContent_Info_ctl00_MakePurchase1_btnMakePurchase" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_MainContent_Info_ctl00_MakePurchase1_btnMakePurchase')" style="width:180px;">
</td>
</tr>
<tr>
<td width="214" rowspan="2">
<div id="ctl00_MainContent_Info_ctl01_upd_small"> 10000 </div>
</td>
<td width="214">
<input name="ctl00$MainContent$Info$ctl01$MakePurchase1$txtPurchasePrice" type="text" maxlength="30" id="ctl00_MainContent_Info_ctl01_MakePurchase1_txtPurchasePrice" style="width:180px;text-align: center">
</td>
</tr>
<tr>
<td>
<input type="submit" name="ctl00$MainContent$Info$ctl01$MakePurchase1$btnMakePurchase" value="Купить" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$Info$ctl01$MakePurchase1$btnMakePurchase", "", true, "", "", false, false))" id="ctl00_MainContent_Info_ctl01_MakePurchase1_btnMakePurchase" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_MainContent_Info_ctl01_MakePurchase1_btnMakePurchase')" style="width:180px;">
</td>
</tr>
</table>
<script type="text/javascript">
document.getElementById('ctl00_MainContent_Info_ctl00_MakePurchase1_btnMakePurchase').onclick = function()
{ var price1 = document.getElementById('ctl00_MainContent_Info_ctl00_upd_small');
var price2 = document.getElementById('ctl00_MainContent_Info_ctl00_Purchase1_txtPurchasePrice');
price2.value = price1.innerText;
}
</script>
</body>
</html>
Как сделать чтобы при нажатии на любую кнопку бралось значение из ряда слева которое находится в той же строке, что и кнопка.
ID элементов генерируются на чужой странице и кол-во строк с кнопками может меняться.
Вот мой скрипт, но он работает только на кнопке которую явно указываешь
<script type="text/javascript">
document.getElementById('ctl00_MainContent_Info_ctl00_MakePurchase1_btnMakePurchase').onclick = function()
{ var price1 = document.getElementById('ctl00_MainContent_Info_ctl00_upd_small');
var price2 = document.getElementById('ctl00_MainContent_Info_ctl00_Purchase1_txtPurchasePrice');
price2.value = price1.innerText;
}
</script>