document.getElementById выборка ID по маске
подскажите, как реализовать подсчет значений элемента input
<td><input class="digits6" type="text" id="count_price_disc[1]" value="100" readonly> руб.</td> <td><input class="digits6" type="text" id="count_price_disc[8]" value="555" readonly> руб.</td> <td><input class="digits6" type="text" id="count_price_disc[22]" value="600" readonly> руб.</td> такой вариант не подходит
for(var i = 0; i < 1000; i++) {
total_price += Number(document.getElementById('count_price_disc['.i.']').value);
}
т.к. элементы идут не последовательно: count_price_disc[1], count_price_disc[2], count_price_disc[3] и т.д., а вразброс, поэтому последовательный прогон циклом не работает, к томуже кол-во элементов не предопределено ( нужно что-то вроде проссумировать по маске, взять все ID содержащие 'count_price_disc[' помогите решить проьлему! |
<td><input class="digits6" type="text" id="count_price_disc[1]" value="100" readonly> руб.</td>
<td><input class="digits6" type="text" id="count_price_disc[8]" value="555" readonly> руб.</td>
<td><input class="digits6" type="text" id="count_price_disc[22]" value="600" readonly> руб.</td>
<script type="text/javascript">
var total_price = 0,
els = document.getElementsByTagName( 'input' );
for( var el, i = 0; el = els[ i++ ]; ) {
if ( /^count_price_disc/.test( el.id ) ) {
total_price += Number( el.value );
}
}
alert( total_price );
</script>
|
2devote, просто огромнейшее спасибо!
|
Цитата:
|
Цитата:
|
Цитата:
count_price_disc[8] Т. к. таким образом PHP принимает массив в запросе, то тут все очевидно. Но зачем он создает массив из 23 элементов (для 3-х в форме) для меня остается загадкой. |
| Часовой пояс GMT +3, время: 01:58. |