Click to See Complete Forum and Search --> : get method form situation


havey
07-08-2003, 09:36 AM
I have a form that has two sets of radios running independently,
1st set is called wor and the second set is called wok, I run a function that adds wor+wok to produce a value for the variable "tot". My situation is that I don't want to send wor and wok into the url, I have a few more forms to pass the url string and parse it from, but they automatically get strung along, I don't need tose value pairs....and I believe they are causeing the NaNs:
Language.htm?age=10&edu=20&occ=4&gua=NaN& reg=NaN& tot=16&wor=16&wok=2

the previous forms url is fine:
Experience.htm?age=10&edu=20&occ=14&gua=10 & reg=5

Is there a way to have a radio button form using the get method to another form not have the radio buttons value pairs pass in the url? Or a way to deal with the NaNs
Thank You forum and supporters!

more page code below:

<!-- Begin
var tot = "";

function Process(){
var firstRG = document.f6.wor;
var secRG = document.f6.wok;
var t1 = 0,t2 = 0,tot = 0;
for(var n=0;n<firstRG.length;n++){
if(firstRG[n].checked){
t1 = parseInt(firstRG[n].value);
break;
}
}

for(var x=0;x<secRG.length;x++){
if(secRG[x].checked){
t2 = parseInt(secRG[x].value);
break;
}
}
tot = t1+t2;
if(tot>16){
tot = 16;
}
document.f6.tot.value = tot;
}


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;
}

// End -->
</script>

<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="">
<input type="hidden" name="tot" value="">

havey
07-08-2003, 09:54 AM
figured it out:

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")+4,sStr.length));
va4 = parseInt(sStr.substring(sStr.indexOf("gua")+4,sStr.length),10);
va5 = parseInt(sStr.substring(sStr.indexOf("reg=")+4,sStr.length));

and i just ignor the wor and wok in the url.

Can someone explain this line to me:
va4 = parseInt(sStr.substring(sStr.indexOf("gua")+4,sStr.length),10);

[1]cause i can't seem to figure out why the number +4 and why sometimes ),10); with the ,10

[2]and can't figure out why +4 only works with "gua" and not "gua="

[3]and am i goging to have a browser compatibility issue with this?

hallim
07-08-2003, 12:18 PM
va4 = parseInt(sStr.substring(sStr.indexOf("gua")+4,sStr.length),10);

parseInt will return the integer value of numerals in a string, and it will accept two values. First value is the string itself, and the second value is the radix which specifies the base number to return (in this case base 10). Its optional, as base 10 is the default.

In your case the string is a substring of sStr. The substring method looks for an instance of 'gua', then adds 4 spaces to the start of the substring. If the first character in your substring is not a number, parseInt won't work. Could this be your problem with 'gua='?