PDA

View Full Version : syntax error :(


havey
04-24-2003, 05:44 PM
Can someone please look over the code to see what doing wrong and causing the Syntax error, thnks

function Process (){
var firstRG = document.f6.wor; //first radio button group array
var secRG = document.f6.wok; //second radio button group array
var val1 = 0,val2 = 0,tot = 0;
//get value from first group
for(var n=0;n<firstRG.length;n++){
if(firstRG[n].checked){
val1 = parseInt(firstRG[n].value);
break;
}
}

for(var x=0;x<secRG.length;x++){
if(secRG[x].checked){
val2 = parseInt(secRG[x].value);
break;
}
}
tot = val1+val2;

}

var sStr = document.location.search;
var val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.indexOf(",")));
var sum = (+tot)+((!isNaN(val))?val:0);
data = sStr.substring(sStr.indexOf(","),sStr.length)+",tot="+(+tot);
document.f6.action="Language.htm?tot="+sum+data ;
//return true;
} //**syntax error line#

cheesebagpipe
04-24-2003, 05:53 PM
{ --- 5
} --- 6

This:

break;
}
}
tot = val1+val2;

}

...closes the function prematurely.

havey
04-24-2003, 05:59 PM
but no matter where i PLace } i get a syntax at that line? I can place it at teh end of the whole process and i'll get a syntax at that line....??

cheesebagpipe
04-24-2003, 06:04 PM
Curly braces - delineating code blocks - come in pairs. You've got an extra 'righty' there, no sense arguing about it. Those last seven lines are outside the function, with a single 'righty' and an illegal return statement. Lose the red one....

havey
04-24-2003, 06:12 PM
ohh... misunderstood your previous post... ahh.. things are working well now .. thank you

liorean
04-24-2003, 06:19 PM
Does this work better?function Process(){
var
firstRG=document.f6.wor, //first radio button group array
secRG=document.f6.wok, //second radio button group array
val1=0,
val2=0,
tot=0,
l=firstRG.length,
k=secRG.length; //get value from first group
while(l-->0){
if(firstRG[l].checked){
val1=parseInt(firstRG[l].value);
break;
}
}
while(k-->0){
if(secRG[k].checked){
val2=parseInt(secRG[k].value);
break;
}
}
tot=val1+val2;
var
sStr=document.location.search,
val=parseInt(sStr.slice(sStr.search(/=/)+1,sStr.search(/,/))),
sum=(+tot)+((!isNaN(val))?val:0),
data=sStr.slice(sStr.search(/,/),sStr.length)+",tot="+(+tot);
document.f6.action="Language.htm?tot="+sum+data;
return true;
}

Just a question: why (+tot)?