Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts

    different code to different browsers

    I have a bit of code that I'm having problems with - this works in FF but not in IE...
    Code:
    arrProducts[i] = 
    document.addform.eval('unitcost'+i).value.replace(/\|\,/g,'');
    so I changed it to
    Code:
    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?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what's the error in FF?
    *keep it simple (TM)

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Code:
    document.addform.elements["unitcost"+i] has no properties

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    let's see the whole loop, plz!
    *keep it simple (TM)

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Code:
    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);
    }
    }
    
    }

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    without the serverside code, thanks. only need the fully parsed JS, thank you!
    *keep it simple (TM)

  • #7
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    ...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.

    Code:
    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);
    }
    }
    
    }

  • #8
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    do you have these elements named in your form?

    - unitcost0
    - unitcost1

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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.

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

  • #10
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by NancyJ
    its asp not php
    that's alright. no need to apologise, that's not your fault!

    Quote Originally Posted by NancyJ
    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

    Quote Originally Posted by NancyJ
    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.
    *keep it simple (TM)

  • #11
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Quote Originally Posted by martin_narg
    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

  • #12
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Hehe, I misread

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

    cheers

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #13
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    ...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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •