/    Sign up×
Community /Pin to ProfileBookmark

parsing form values

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 i have so far:
<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”.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@haveyauthorJul 07.2003 — figured it out!

va2 = parseInt(sStr.substring(sStr.indexOf("edu=")+4,sStr.length));
Copy linkTweet thisAlerts:
@Jeff_MottJul 07.2003 — Here's an alternative if you want a more generic query string parser to handle all cases.

[thread]162208[/thread]
Copy linkTweet thisAlerts:
@haveyauthorJul 07.2003 — Ahhhhh....

form5 produces an invalid url??:

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="">
×

Success!

Help @havey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...