Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding script 1

Status
Not open for further replies.

dakoz

Programmer
Feb 2, 2002
74
hi there i have a script which when you check some checkboxes in a form it calculates the sum of MBs checked and the price which will cost. The price changes every 700MB (One CD)
I Give the user the following output :

450MB
20 Euro --> Check Out

i want to give

450MB (1CD)
20 Euro -->Check Out

This is not my script and i get comfuzed where to put the cd counter.. could you help me?? This is the code:

<script language=&quot;JavaScript&quot;>
<!--
function schet(f,size){
var cd=new Array();
cd[0]=&quot;0&quot;;
cd[1]=&quot;13&quot;;
cd[2]=&quot;23&quot;;
cd[3]=&quot;35&quot;;
cd[4]=&quot;45&quot;;
cd[5]=&quot;54&quot;;
cd[6]=&quot;63&quot;;
cd[7]=&quot;70&quot;;
cd[8]=&quot;77&quot;;
cd[9]=&quot;84&quot;;
cd[10]=&quot;90&quot;;
size=size-0;
summa=document.list.summa.value;
summa=summa-0;
if (f.checked) {
bew=document.list.price.value;
if (bew==0) {
document.list.price.value=cd[1];
with(document.list)
ress.innerText = cd[1]+&quot; euro&quot;;
}
summa1=summa+size;
summa1 = Math.round(summa1*10)/10;
document.list.summa.value=summa1;
with(document.list)
res.innerText = summa1;
for (k=1;k<100;k++){
if (summa<k*700){
i=k*700;
break;
}
}
if ((summa<i)&&(summa1>=i)){
o=k+1;
document.list.price.value=cd[o];
with(document.list)
ress.innerText = cd[o]+&quot; euro&quot;;
}
}
else {
summa1=summa-size;
summa1 = Math.round(summa1*10)/10;
document.list.summa.value=summa1;
with(document.list)
res.innerText = summa1;
for (k=1;k<100;k++){
if (summa<k*700){
i=(k-1)*700;
break;
}
}
if ((summa>i)&&(summa1<=i)){
o=k-1;
document.list.price.value=cd[o];
with(document.list)
ress.innerText = cd[o]+&quot; euro&quot;;
}
}

}
-->
</script>

and i the main body if one box is checked i give dynamically the MB Size and price

<span id=res></span><input type=&quot;hidden&quot; name=&quot;summa&quot; value=&quot;0&quot;> MB
<HR width=80% style=&quot;height: 1pt;color:DFDFDF;&quot;>
Price: <span id=ress>0 euro</span><input type=&quot;hidden&quot; name=&quot;price&quot; value=&quot;0&quot;><BR>
<input type=&quot;submit&quot; value=&quot;Check Out&quot;>
<input type=&quot;hidden&quot; name=&quot;mode&quot; value=&quot;listing&quot;></form>
<A Href=&quot;#&quot;><FONT FACE=VERDANA SIZE=1>Buy All (9 CDS)</FONT></A>
</CENTER><BR>
 
This code is very difficult to follow - why not reduce the size of the functions ?

what do these fgures apply to ?
var cd=new Array(0,13,23,35,45,54,63,70,77,84,90);

if they apply to the amount of files on cds ie

cd[1] has 13 files and 1 cd

then why not just use the array number

ress.innerText = cd[o]+&quot; euro (&quot; + o + &quot; CD)&quot;;
 
the code is kinda messy... i had an external programmer .

But you helped me a lot with this :
ress.innerText = cd[o]+&quot; euro (&quot; + o + &quot; CD)&quot;;


i didn't think of it. Thanx a Lot Man
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top