获取javascript函数运行所需的帮助

时间:2016-12-11 17:01:15

标签: javascript

[编辑] 已解决:在将调用触发到另一个脚本后,我立即将触发器移动到ajax函数中。在添加“警报”后,我能够解决这个问题。到JS函数。所以有其他相对新手的提示:在你的函数中使用警报来更清楚它们何时被触发,以及它们是否被触发。 [/编辑]

以下代码是类似计算器的表单。通过计算器按钮将值输入文本框,然后输入'现金'单击提交按钮以激活对另一个脚本的ajax调用。然后该脚本在同一页面中显示输出。

一切正常。

但是,具有该值的文本框应该清空' onsubmit'但那部分不起作用。请帮助我理解为什么JS功能' clearCalc'似乎没有被触发。

[编辑] 我为该功能添加了一个警报,它很快就被触发了。 onosubmit在提交表单之前触发它。我需要在ajax被触发后清除文本框值。我怎么能得到那个?

[/编辑]

print qq(
  <div id='till_keypad'>
  <form name="vform" id="vform" onsubmit="clearCalc(vform);">
    <div>
    <label for="till_payment_input"><strong>Amount:</strong> </label>
      <input type="text" id='till_payment_input' name="till_payment_input" placeholder="Amount paid" />
    </div> 
    <div id='row1'>
      <input type="button" class="fbutton" name="7" value="7" id="7" onClick="document.vform.till_payment_input.value+='7'"/>
      <input type="button" class="fbutton" name="8" value="8" id="8" onClick="document.vform.till_payment_input.value+='8'"/>
      <input type="button" class="fbutton" name="9" value="9" id="9" onClick="document.vform.till_payment_input.value+='9'"/>
      <input type="button" class="rButton" name="refund" value="Refund" id="refund" />
    </div>
    <div id='row2'>
      <input type="button" class="fbutton" name="4" value="4" id="4" onClick="document.vform.till_payment_input.value+='4'"/>
      <input type="button" class="fbutton" name="5" value="5" id="5" onClick="document.vform.till_payment_input.value+='5'"/>
      <input type="button" class="fbutton" name="6" value="6" id="6" onClick="document.vform.till_payment_input.value+='6'"/>
      <input type="button" class="rButton" name="returns" value="Returns" id="returns" />
    </div>
    <div id='row3'>
      <input type="button" class="fbutton" name="1" value="1" id="1" onClick="document.vform.till_payment_input.value+='1'"/>
      <input type="button" class="fbutton" name="2" value="2" id="2" onClick="document.vform.till_payment_input.value+='2'"/>
      <input type="button" class="fbutton" name="3" value="3" id="3" onClick="document.vform.till_payment_input.value+='3'"/>
      <input type="button" class="rButton" name="credit_note" value="Credit Note" id="credit_note" />
    </div>
    <div id='row4'>
      <input type="button" class="fbutton" name="0" value="0" id="0" onClick="document.vform.till_payment_input.value+='0'"/>
      <input type="button" class="fbutton" name="10" value="." id="10" onClick="document.vform.till_payment_input.value+='.'"/>
      <input type="button" class="fbutton" name="11" value="00" id="11" onClick="document.vform.till_payment_input.value+='00'"/>
      <input type="button" class="rButton" name="discount" value="Discount" id="discount" />
    </div>
    <div id='row5'>
      <input type="submit" class="cashButton" name="paid_with" value="CASH" id="paid_with" />
      <input type="submit" class="cardButton" name="paid_with2" value="CARD" id="paid_with2" />
      <input type="submit" class="voucherButton" name="paid_with3" value="VOUCHER" id="paid_with3" />
      <input type="submit" class="voucherButton" name="" value="" id="" /> 
    </div>
    <div id='row6'>
      <button type="button" class="voidButtonA" onclick="ClearFields();">CE</button>
      <button type="button" class="voidButtonA" onclick="removeChar();">C</button>
      <input type="button" class="voidButtonB" name="void" value="VOID Sale" id="void" />
      <input type="button" class="voidButtonB" name="" value="" id="" />
    </div>
    <div id='row7'>
      <input type="submit" class="oButton" name="back_office" value="Back Office" id="back_office" />
      <input type="submit" class="oButton" name="x_reading" value="X Reading" id="x_reading" />
      <input type="submit" class="oButton" name="y_reading" value="Y Reading" id="y_reading" />
      <input type="submit" class="oButton" name="" value="" id="" /> 
    </div>


    <div class='clear'> </div>);





print qq(
  </form>
</div>
<div class='clear'></div>);





print qq(
<script language="javascript" type="text/javascript">
function clearCalc(vform) {
  // vform.till_payment_input.value == "";
return  document.getElementById("till_payment_input").value = "";
} 
</script>);

0 个答案:

没有答案