We create a script that gets the innerhtml of a element with specific class. This works perfect for the first <table>
. But the script does not work for the second <table>
.
I guess this is due to the getElementbyID. How can we edit our script, so it will work for each table?
HTML:
<table>
<tbody>
<tr>
<td class="image" rowspan="8">
<div class="myedit" id="MyEdit"></div>
</td>
<td class="order" colspan="2">Text</td>
</tr>
<tr>
<td>
<div class="input-box">
<ul id="options-183-list" class="options-list">
<li class="product-option active">
<span class="input-radio">
<input type="radio" class="radio validate-one-required-by-name product-custom-option" onclick="opConfig.reloadPrice()" checked="" name="options[183]" id="options_183_2" value="591" price="0">
</span>
<label for="options_183_2">
<span class="option-name">Product option 1</span>
<span class="option-sku">SKU1</span>
<span class="price-notice default">€0</span>
</label>
</li>
<li class="product-option">
<span class="input-radio">
<input type="radio" class="radio validate-one-required-by-name product-custom-option" onclick="opConfig.reloadPrice()" name="options[183]" id="options_182_2" value="590" price="0">
</span>
<label for="options_183_1">
<span class="option-name">Product option 2</span>
<span class="option-sku">SKU2</span>
<span class="price-notice default">€0</span>
</label>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="image" rowspan="8">
<div class="myedit" id="MyEdit"></div>
</td>
<td class="order" colspan="2">Text</td>
</tr>
<tr>
<td>
<div class="input-box">
<ul id="options-181-list" class="options-list">
<li class="product-option active">
<span class="input-radio">
<input type="radio" class="radio validate-one-required-by-name product-custom-option" onclick="opConfig.reloadPrice()" checked="" name="options[181]" id="options_181_2" value="578" price="0">
</span>
<label for="options_181_2">
<span class="option-name">Product option 1</span>
<span class="option-sku">SKU1</span>
<span class="price-notice default">€0</span>
</label>
</li>
<li class="product-option">
<span class="input-radio">
<input type="radio" class="radio validate-one-required-by-name product-custom-option" onclick="opConfig.reloadPrice()" name="options[181]" id="options_181_2" value="579" price="0">
</span>
<label for="options_181_1">
<span class="option-name">Product option 2</span>
<span class="option-sku">SKU2</span>
<span class="price-notice default">€0</span>
</label>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function () {
$('input').click(function () {
var sku = $('input:checked').closest('.product-option').find('.option-sku').html();
document.getElementById("MyEdit").innerHTML = sku
});
var sku = $('input:checked').closest('.product-option').find('.option-sku').html();
document.getElementById("MyEdit").innerHTML = sku
});
</script>