HTML输入类型编号,获取价值

时间:2017-11-25 03:30:10

标签: javascript html

嗨,我正在为我的一个项目开店,目前在设置购买多件商品的价格方面遇到了一些麻烦。我遇到的麻烦是更新一个玩家想要买多少的价格预测。而我无法弄清楚当前的数字,所以我可以用它来增加价格

<table>
<tr>
  <td align="left">Owned: 25
    <?php echo number_format($buildings['mine']); ?>
  </td>
  <td align="right" valign="bottom">Amount: <input type="number" name="house" min="0" max="100000" /><input type="submit" name="buy" value="Buy" /></td>
</tr>
<tr>
  <td>
  Cost: <?php echo number_format($buildings['mine']) * 5000 * 0.05 + 5000; ?>
  </td>
</tr>
</table>

1 个答案:

答案 0 :(得分:0)

我确实管理了一个解决方案,它有点粗糙,没有立即更新,但它仍然按照我需要的方式工作

&#13;
&#13;
var output1 = document.getElementsByName("OUTPUT1")[0];

function changeInput(e) {
  // fill tolhouse with php
  var tolhouse = 1;
  //Calculate current price based on how many owned + price increse
  var curprice = (input1.value * ((tolhouse * 25000) * 0.05) + 25000);
   //calc predicted prices based off curpice + price incease
  var calc = input1.value * curprice + (input1.value * curprice * 0.05);
  output1.value = calc;
}

input1.onchange = changeInput;
&#13;
<form name="TESTING">
  <table border="1" width="600" height="200" cellpadding="10" cellspacing="3">
    <tr>
      <th colspan="2">
        <h1>TESTING</h1>
      </th>
    </tr>
    <tr>
      <th>
        <h3>INPUT</h3>
      </th>
      <th>
        <h3>OUTPUT</h3>
      </th>
    </tr>
    <tr></tr>
    <td><input type="number" name="INPUT1" /></td>
    <td><input type="text" name="OUTPUT1"></td>
    <table>
&#13;
&#13;
&#13;