View Full Version : variable addition :: onSubmit

01-20-2003, 03:09 AM
age field value number is from form1, and was sent to form2 via the url. I've decoded the url and used document.write to display the number on the page of form2.

I'm having a problem adding age number(from form1) to edu number value selection, from form2, to get a non cancatenated(sp?) number, like 4+5=9, NOT 4+5=45
this is what i've been working on, with many troubles and hardships, i was wondering is someone could ease the pain?:

<form name="form2" action="Occupational_Demand.htm" method="GET" onsubmit=var sum = parseInt(document.form1.age.value)+parseInt(document.form2.edu.options[document.form2.edu.selectedIndex].value);

the goal is to add the numbers and send them via url to the next form, but so far no luck. I don't want to stray from what i have; to use hidden fields, or use fames. Thanks

01-20-2003, 04:42 AM
Pleae do help, maybe my wording is poor, lets see......

passed value from form1 to form2 via url. code below is on form2 to send to form3 (Occupational_Demand.htm). Why is this not working, only form2 value is being passed via url to form3, not the summation of form1 and form2 values, like 4+5=9, 9 passed to form3

<form name="form2" action="Occupational_Demand.htm" method="GET" onSubmit="document.location="Occupational_Demand.htm?edu="+(parseInt(document.form1.age.value)+parseInt(document.form2.edu.value))";>

Roy Sinclair
01-20-2003, 09:43 PM
If form1 is on your first page and you had to get it's value from a URL then you can't be getting it's value directly from the form as you try to pass it onto form3. In short document.form1.age.value isn't available, you need to use the field you stored in into on form2 instead.

01-20-2003, 09:50 PM
thanks for the reply i got it working:

var sStr = document.location.search;
var val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.indexOf(",")));
var sum = parseInt(document.f2.edu[j].value)+((!isNaN(val))?val:0);
data = sStr.substring(sStr.indexOf(","),sStr.length)+ ",(edu="+parseInt(document.f2.edu[j].value)+")";
document.f2.action="Occupational_Demand.htm?edu="+sum+data ;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum