...

View Full Version : parsing form data



havey
07-07-2003, 10:25 PM
doing this client side, I have form 1 sending its value to form 2. On form 2 i have,
<head>
<script type="text/javascript">
<!-- Begin

window.onload = updateRunningScore;
function updateRunningScore(){
var sStr = document.location.search;
val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
document.getElementById("currentScore").innerHTML = "Your score up to this point is = "+((!isNaN(val))?val:0);
document.f2.age.value = val;
}

// End -->
</script>

<body>
<input type="hidden" name="age" value="">

so my form 3 url after form 2 submits is Occupational_Demand.htm?age=10&edu=20 ///exactly what i want it to be, 10 and 20 are the choosen values.

now on submit of form 3 i'm trying to have the form4 url just extend the string to include the form3 value pair, like so:
Guaran.htm?age=10&edu=20&occ=14
but i keep losing it:
Guaran.htm?age=10&edu=NaN&occ=14

would appreciate some direction, thanks

this is what incorrectly have:
<script type="text/javascript">
<!-- Begin
window.onload = updateRunningScore;
function updateRunningScore(){
var sStr = document.location.search;
val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+1,sStr.length));
document.getElementById("currentScore").innerHTML = "Your score up to this point is = "+((!isNaN(val))?val:0);
document.f3.age.value = val;
document.f3.edu.value = va2;
}
// End -->
</script>
</head>
<body>
<input type="hidden" name="age" value="">
<input type="hidden" name="edu" value="">

BTW, i'm working of the addition of the string values for the "currentScore".

havey
07-07-2003, 11:00 PM
figured it out:

va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length));

Roy Sinclair
07-07-2003, 11:08 PM
Originally posted by havey
figured it out:

va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length),10);

Add the part in red above or your users will get strange results when they enter numbers with leading zeroes (without the "radix" specified for base 10, a leading zero will cause parseInt to assume the user entered an Octal number).

havey
07-08-2003, 01:12 AM
I though that maybe your suggestion, Roy, would solve my problem, thanks for the tip, this is my problem:

this funny url from form 5 to 6:
Experience.htm?age=10&edu=20&occ=NaN&gua=NaN&reg=5

the form preceeding it is fine:
Development.htm?age=10&edu=20&occ=4&gua=10

why the NaNs???

this is Development.htm:
<head>
<script type="text/javascript">
<!-- Begin
window.onload = updateRunningScore;
function updateRunningScore(){

var sStr = document.location.search;
val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length));
va3 = parseInt(sStr.substring(sStr.indexOf("occ=")+5,sStr.length));
va4 = parseInt(sStr.substring(sStr.indexOf("gua=")+6,sStr.length));

document.f5.age.value = val;
document.f5.edu.value = va2;
document.f5.occ.value = va3;
document.f5.gua.value = va4;

document.getElementById("currentScore").innerHTML = "Your score up to this point is = "+((!isNaN(val))?val:0);
}
// End -->
</script>

</head><body>

<form name="f5" method="GET" action="Work_Experience.htm">
<input type="hidden" name="age" value="">
<input type="hidden" name="edu" value="">
<input type="hidden" name="occ" value="">
<input type="hidden" name="gua" value="">

and this is Experience.htm:

<head>
window.onload = updateRunningScore;
function updateRunningScore(){

var sStr = document.location.search;
val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length));
va3 = parseInt(sStr.substring(sStr.indexOf("occ=")+5,sStr.length));
va4 = parseInt(sStr.substring(sStr.indexOf("gua=")+6,sStr.length));
va5 = parseInt(sStr.substring(sStr.indexOf("reg=")+7,sStr.length));

document.f6.age.value = val;
document.f6.edu.value = va2;
document.f6.occ.value = va3;
document.f6.gua.value = va4;
document.f6.reg.value = va5;
}

</head>

<body>
<form name="f6" method"GET" action="Language.htm">
<input type="hidden" name="age" value="">
<input type="hidden" name="edu" value="">
<input type="hidden" name="occ" value="">
<input type="hidden" name="gua" value="">
<input type="hidden" name="reg" value="">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum