Click to See Complete Forum and Search --> : variable summation onSubmit


catchup
01-19-2003, 02:40 PM
a field passed and written to this form, from a previous form:
var loc=""+document.location;
loc = loc.indexOf("?age=")!=-1?loc.substring(loc.indexOf("?age=")+5,loc.length):"";
var age = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
document.write(age);

problem lyes in adding age and new form selection value with the previous form selection (age) onsubmit:
<form name="f2" action="Occupational_Demand.htm" method="GET" onSubmit="var sum = parseInt(document.f1.age.value)+parseInt(document.f2.edu.options[document.f2.edu.selectedIndex].value);
document.location="Occupational_Demand.htm?edu="+sum">

thanks for your input! much appreciated

khalidali63
01-19-2003, 02:56 PM
put all of your code here
may be a zipped file

Khalid

catchup
01-19-2003, 03:06 PM
The problem is on the second form submitting to the 3rd, they are all inter joined, the first form post using the GET method to this page:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Education</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkRadios() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if(el[i].type == "radio") {
var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
var itemchecked = false;
for(var j = 0 ; j < radiogroup.length ; ++j) {
if(radiogroup[j].checked) {
itemchecked = true;
break;
}
}
if(!itemchecked) {
alert("Please select an Education Level");
if(el[i].focus)
el[i].focus();
return false;
}
}
}
return true;
}
// End -->
</script>

</head>

<body>

<p align="center"><font face="Arial, Helvetica, sans-serif" color="#000099" size="+1"><b>Skilled
Worker Self-Assessment</b></font>
<p align="center"><font face="Arial, Helvetica, sans-serif" color="#000099"><b>Factor
2 - Education&nbsp;</b> <font size="-1">(maximum 20 points)</font></font></p>
<p align="center">
<font face="Arial,Helvetica,sans-serif" size="-1">Your score up to this
point is:&nbsp;</font><SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var loc=""+document.location;
loc = loc.indexOf("?age=")!=-1?loc.substring(loc.indexOf("?age=")+5,loc.length):"";
var age = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
document.write(age);
// End -->
</script></p>
<p ALIGN="left" style="text-indent: 0; line-height: 100%">The principal applicant’s highest
level of education:<br>
(<a href="Education_Definitions.htm">Click for definitions of various education
levels</a>.)<!-- FORM STARTS HERE -->
</p>
<form name="f2" action="Occupational_Demand.htm" method="GET" onSubmit="return checkRadios(this)","var sum = parseInt(document.f1.age.value)+parseInt(document.f2.edu.options[document.f2.edu.selectedIndex].value);
document.location="Occupational_Demand.htm?edu='+sum'">
<table cellSpacing="10" cellPadding="0" width="662" border="0">
<tbody>
<tr>
<td align="left" width="604">
<div align="left">
<font face="Times New Roman" size="3">I have a second or third level university degree (e.g., masters or doctorate)</font>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="20" name="edu"></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<font face="Times New Roman" size="3">I have a university degree or a diploma that required at least three (3) years of full time post-secondary study&nbsp;
OR&nbsp; I have an apprenticeship or a trade certificate based on at least three (3) years of combined education and on-the-job training.</font>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="16" name="edu"></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<font face="Times New Roman" size="3">I have completed a 1 to 2 year post-secondary program.</font>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="14" name="edu"></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<font face="Times New Roman" size="3">I have completed secondary school (high school).</font>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="10" name="edu"></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<font face="Times New Roman" size="3">I have not completed secondary school.</font>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="0" name="edu"></font></td>
</tr>
</tbody>
</table>
<p><input type="submit" value="Next">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="Clear" name="Reset"></p>
</form>
</body>
</html>

catchup
01-19-2003, 06:59 PM
PLease....

khalidali63
01-19-2003, 09:58 PM
I have made several changes to make your code work and properly as required.

Please see the attached zip file

cheers

Khalid

catchup
01-20-2003, 12:02 AM
Dude, i read it and it seem to want to work, but when i tried it, the same problem as i had b4, the summations don't add and go to the next form????

catchup
01-20-2003, 12:39 AM
My apologies, it workes on the desktop on my computer but not on the web when i ftp.... why would this be? hmmm......

khalidali63
01-20-2003, 12:48 AM
you should be able to do that with pety
simple functionality.
Anyways,
I have attached an updated zip file for you.
try it.

Khalid

khalidali63
01-20-2003, 12:50 AM
you might want to make sure that the URL location actually is a valid one,since a web browser might read relative url paths differently as compare to the absolute.

Khalid

catchup
01-20-2003, 12:57 AM
U R GOD, and its scaring me, besides im in winnipeg and even though its a good 16 hours away i can still feel your power. cheers

catchup
01-20-2003, 01:38 AM
1 other thing if you wouldn't mind, I displaying the field values from the previous form, like so:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var loc=""+document.location;
loc = loc.indexOf("?age=")!=-1?loc.substring(loc.indexOf("?age=")+5,loc.length):"";
var age = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
document.write(age);
// End -->
</script>

so on the second form, the first form field value is displayed, and on the the third form, the second fields value, and so forth, but now its picking up the data = sStr.substring(sStr.indexOf(","),sStr.length)+ ",(edu="+parseInt(document.f2.edu[j].value)+")";

like so: Your score up to this point is: 10,(age=10)

how can this be changed so that it only reads: Your score up to this point is: 10

thanks again.

khalidali63
01-20-2003, 01:42 AM
do you mean that at any given page it should print phrase
:Your score before completing this page = X;

?

Khalid

catchup
01-20-2003, 01:44 AM
yes

khalidali63
01-20-2003, 01:56 AM
Here you go

Khalid