...

View Full Version : different code to different browsers



NancyJ
07-06-2005, 10:59 AM
I have a bit of code that I'm having problems with - this works in FF but not in IE...

arrProducts[i] =
document.addform.eval('unitcost'+i).value.replace(/\|\,/g,'');


so I changed it to


arrProducts[i] =
document.addform.elements['unitcost'+i].value.replace(/\|\,/g,'');


and that works in IE but not in FF.... how can I either fix it to work in both or change it give the right code to each browser?

jbot
07-06-2005, 11:04 AM
what's the error in FF?

NancyJ
07-06-2005, 11:10 AM
document.addform.elements["unitcost"+i] has no properties

jbot
07-06-2005, 11:12 AM
let's see the whole loop, plz!

NancyJ
07-06-2005, 11:19 AM
function setCosts(){
subtotal = 0;
for( i = 0; i < <%=ubound(arrOrder)+1%>; i++)
{
arrProducts[i] = document.addform.elements['unitcost'+i].value.replace(/\|\,/g,'');
subtotal = subtotal + (arrProducts[i] * document.addform.elements['prodquantities'+i].value);
document.addform.elements['prodtotal'+i].value = formatCurrency((arrProducts[i] * document.addform.elements['prodquantities'+i].value)* ((100 - document.addform.discount.value)/100));
}
var country = document.addform.ShipCountryID.options[document.addform.ShipCountryID.selectedIndex].value;
for(i = 0;i< counter; i++){
if (arrIDs[i] == country){
document.addform.delivery.value = formatCurrency(arrCosts[i]);
subtotal = subtotal * ((100 - document.addform.discount.value)/100)
document.addform.total.value = formatCurrency(arrCosts[i]+subtotal);
}
}

}

jbot
07-06-2005, 11:24 AM
without the serverside code, thanks. only need the fully parsed JS, thank you!

NancyJ
07-06-2005, 11:28 AM
...its asp not php ;) and the parsed output is identical except for the upper bound of the loop... but here you go.. though this is variable and can change depending on the number of products orders.


function setCosts(){
subtotal = 0;
for( i = 0; i < 1; i++)
{
arrProducts[i] = document.addform.elements['unitcost'+i].value.replace(/\|\,/g,'');
subtotal = subtotal + (arrProducts[i] * document.addform.elements['prodquantities'+i].value);
document.addform.elements['prodtotal'+i].value = formatCurrency((arrProducts[i] * document.addform.elements['prodquantities'+i].value)* ((100 - document.addform.discount.value)/100));
}
var country = document.addform.ShipCountryID.options[document.addform.ShipCountryID.selectedIndex].value;
for(i = 0;i< counter; i++){
if (arrIDs[i] == country){
document.addform.delivery.value = formatCurrency(arrCosts[i]);
subtotal = subtotal * ((100 - document.addform.discount.value)/100)
document.addform.total.value = formatCurrency(arrCosts[i]+subtotal);
}
}

}

martin_narg
07-06-2005, 11:32 AM
do you have these elements named in your form?

- unitcost0
- unitcost1

m_n

glenngv
07-06-2005, 11:33 AM
Try to alert the i variable to see at what point in the iteration of the loop the error occurs. The error might be caused by the index of the arrProducts array does not correspond to the field name suffix.


arrProducts[i] = document.addform.elements['unitcost'+i].value.replace(/\|\,/g,'');

jbot
07-06-2005, 11:34 AM
its asp not php

that's alright. no need to apologise, that's not your fault! ;)


the parsed output is identical except for the upper bound of the loop.

which is what I needed, because I needed to see what you're trying to loop round :rolleyes:


this is variable and can change depending on the number of products orders.

you don't say. that's utterly amazing, that is ;)

anyway, presumably there's no form element named unitcost0, is there?

will need to see your form's HTML to clarify. thanks.

NancyJ
07-06-2005, 11:37 AM
do you have these elements named in your form?

- unitcost0
- unitcost1

m_n

no... in that rendering of the code the only form field was unitcost0 ( the code sepcifically states i < 1 so unitcost1 is not needed) if 2 products were being ordered then there would be both unitcost0 and unitcost1 but the loop would be i <2

martin_narg
07-06-2005, 11:45 AM
Hehe, I misread :rolleyes:

If you could post up the generated form code, then that would be easier to debug.

cheers

m_n

NancyJ
07-06-2005, 11:49 AM
...found the issue, it wasnt anything to do with the javascript or browser... just the products I selected in different browsers heh..
Itr was my asp loop that was the wrong way round, it was appending the product index rather than the order index, which is why the error was intermitent... I think its fixed now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum