Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Быстрый расчет стоимости с input (https://javascript.ru/forum/dom-window/53014-bystryjj-raschet-stoimosti-s-input.html)

dima_riabets 17.01.2015 15:43

Быстрый расчет стоимости с input
 
Почему не работает? (
http://learn.javascript.ru/play/3K4U5b

<!DOCTYPE HTML>
<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.10.2.js'></script>

    <input type="text" maxlength="10" name="price" value="">
    <form id="form_calculator_price_to_uah" onsubmit="return false;" oninput="document.getElementById('rezultat').innerHTML= parseFloat(document.getElementById('a').innerHTML)*parseFloat(document.getElementById('b').innerHTML)">
      <span id="a"></span>x
      <span id="b" style="padding: 0; margin: 0; font-weight: bold;">17</span>=
      <span id="rezultat">N/A</span>грн.</form>
    <script>
      $('input[name="price"]').keyup(function () {
        var value = $(this).val();
        $('#a').text(value);
      });
    </script>
</body>
</html>

danik.js 17.01.2015 16:26

А откуда в форме без полей ввода взяться событию input?

рони 17.01.2015 17:35

dima_riabets,
:-/ :-/ :-/
<!DOCTYPE HTML>
<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  </head>
<body>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

    <form id="form_calculator_price_to_uah" onsubmit="return false;" oninput="document.getElementById('rezultat').innerHTML= parseFloat(document.getElementById('a').innerHTML)*parseFloat(document.getElementById('b').innerHTML)">
    <input type="text" maxlength="10" name="price" value="">
      <span id="a"></span>x
      <span id="b" style="padding: 0; margin: 0; font-weight: bold;">17</span>=
      <span id="rezultat">N/A</span>грн.</form>
    <script>
      $('input[name="price"]').on("input",function () {
        var value = $(this).val();
        $('#a').text(value);

      });
    </script>
</body>
</html>


Часовой пояс GMT +3, время: 15:49.