简体   繁体   English

如何使用javascript将表单值传递给表单中的其他字段

[英]How do I pass form values to other fields in a form with javascript

I'm Working with form validation and fields for the first time without inline event handling. 我第一次使用表单验证和字段,而没有内联事件处理。 I can't find an example of how to pass a integer value, do a operation on it and pass to another field. 我找不到如何传递整数值,对其进行运算并传递给另一个字段的示例。 This is what I'm up against: 我要面对的是:

FORM LOOKS LIKE THIS: 表单外观如下:

ITEM         CONTAINER   QUANTITY PRICE         EXTENDEDCOST
Small Beer   Bottle,Can     ??    @3.99/ea        ??

HTML BITS HTML位

 <form action="#" method="get" name="orderForm" id="orderForm">
 <table id="products">
 <input name="qtySmall" id="qtySmall" type="text" size="4" maxlength="6" value=""   />
 <input name="extSmall" id="extSmall" type="text" size="10" maxlength="60" value="" />

Javascript Java脚本

 window.onload = initForms;

 function initForms()
 {
 document.getElementById("qtySmall").onfocus = detect;
 document.getElementById("qtySmall").onchange = going_away;
 document.getElementById("extSmall").value = passmyvalue; //not sure about this one yet
 }

 function detect()
 {
    alert("works")
 }

 function going_away()
 {
   pass_variable = document.getElementById("qtySmall").value; 
 }

 function passmyvalue()
 {
 // I have no idea how to pass my qty small  multiply it and pass it to the next field box 4 beers * 3.99 = 15.96 in extsmall 
 }

Thanks for the Help 谢谢您的帮助

Not sure if I am understanding your problem here. 不知道我是否在这里理解您的问题。 Can't you just change your going_away function to do the following? 您不能只更改go_away函数以执行以下操作吗?

function going_away() 
{
   pass_variable = document.getElementById("qtySmall").value;
   document.getElementById("extSmall").value = parseInt(pass_variable) * cost;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM