开发者

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

 <form action="#" method="get" name="orderForm"开发者_StackOverflow中文版 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

 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?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜