За последние 24 часа нас посетил 17641 программист и 1672 робота. Сейчас ищут 887 программистов ...

Поочерёдная очистка поля input

Тема в разделе "JavaScript и AJAX", создана пользователем found, 18 июл 2011.

  1. found

    found Активный пользователь

    С нами с:
    18 июл 2011
    Сообщения:
    1
    Симпатии:
    0
    Длинну можно вводить ручками или юзать выпадающий список, нужно чтоб при переключении с одного на другой тип ввода очищалось полей с выведенной ценой автоматически. вот код:
    Функция подсчёта цены
    Код (Text):
    1. function vCalculateCost(leng, discount, isKatushka) {
    2.         var pr = parseInt(document.getElementById('baseprice').value);
    3.  
    4.         if (isKatushka) {
    5.             var katushka = parseInt(document.getElementById('katushka').value);
    6.             if (!katushka) katushka = 0;
    7.             basecine = katushka * 762 * pr;
    8.             leng = katushka * 762;
    9.             document.getElementById('viewprice').value = basecine;
    10.             document.getElementById('length_of_product').value = leng;
    11.             if (discount > 0) {
    12.                 var cine = parseInt(document.getElementById('undiscounted_price').value) * leng;
    13.                 cine = cine - basecine;
    14.                 document.getElementById('allDiscountValue').value = cine;
    15.             }
    16.         } else {
    17.             leng = parseFloat(leng);
    18.             if (!leng) leng = 0;
    19.             var basecine = Math.round(pr * leng);
    20.             document.getElementById('viewprice').value = basecine;
    21.             document.getElementById('katushka').value = 0;
    22.             if (discount > 0) {
    23.                 var cine = parseInt(document.getElementById('undiscounted_price').value) * leng;
    24.                 cine = Math.round(cine - basecine);
    25.                 document.getElementById('allDiscountValue').value = cine;
    26.             }
    27.         }
    28.     }
    Собственно вид странички(без выпадающего списка длинн)
    Код (Text):
    1. <td>
    2.     <a href="#" onclick="TagToTip('howToPage', WIDTH, 450, CLOSEBTN, true, FOLLOWMOUSE, false, FONTSIZE, '12px', BGCOLOR, '#ffffff', BORDERCOLOR, '#ffffff', SHADOWCOLOR, '#ffffff', SHADOWWIDTH, 0); return false;">Äëèíà èçäåëèÿ: <img src="img/question_sign.jpg" width="15" height="15" border="0" /></a> <div style="font-size: 0px; height: 7px;"></div>
    3.     <input type="text" name="length_of_product" id="length_of_product" onkeyup="vCalculateCost(this.value, {$dicsount_present}, false);" class="f45" /> ñì
    4.     <div style="display: none;" id="howToPage">
    5.     <b>{$howToPage.title|stripslashes}</b>
    6.     <br/><br/>
    7.     {$howToPage.text|stripslashes}
    8.     </div>
    9. </td>
    10. <td align="right">
    11.     Цена <div style="font-size: 0px; height: 7px;"></div>
    12.     <input type="text" name="viewprice" id="viewprice" readonly="" class="f74" /> {$smarty.const.MONEY_SIGN}
    13. </td>
    ну и списочек
    Код (Text):
    1. <select name="id[1]" id="attrib-1">
    2.   <option value="1">1 ñì </option>
    3.   <option value="2">2 ñì </option>
    4.   <option value="3">3 ñì </option>
    5.   <option value="4">4 ñì </option>
    6.   <option value="5">5 ñì </option>
    7. </select>
     
  2. bessss

    bessss Активный пользователь

    С нами с:
    10 июн 2008
    Сообщения:
    4
    Симпатии:
    0
    Так причем тут php, с клиентской частью работает javascript