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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up JS not working in FireFox

    Hi, I'm new to JS and been thrown in at the deepend as our developer has just left! You are dealing with a total newbie!

    I have the following script that is not working in FF but is fine in Chrome and IE can anyone tell me what is wrong with it please?!

    Code:
    function showTotalCost(val)
    {
     if(val=='yes')
     {
     if(document.getElementById('secondaryeventtype').value == 'adventure')
    {
    document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) + 100).toFixed(2) + ' (including insurance)';
     }
     else
     {
     document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) + 27).toFixed(2) + ' (including insurance)';
    }
    }
     else
    {
    document.getElementById('totalcost').innerText = document.getElementById('cost').value;
     }
    }
    Code:
    function calculateGroupMembers()
    {
    var iMultiplier;
    if(document.getElementById('txtGroup1Firstname').value != '' || document.getElementById('txtGroup1Surname').value != '' || document.getElementById('txtGroup1Email').value != '')
    {
    iMultiplier=2;
    }
    if(document.getElementById('txtGroup2Firstname').value != '' || document.getElementById('txtGroup2Surname').value != '' || document.getElementById('txtGroup2Email').value != '')
    {
    iMultiplier=3;
    }
     if(document.getElementById('txtGroup3Firstname').value != '' || document.getElementById('txtGroup3Surname').value != '' || document.getElementById('txtGroup3Email').value != '')
    {
     iMultiplier=4;
    }
    if(document.getElementById('txtGroup4Firstname').value != '' || document.getElementById('txtGroup4Surname').value != '' || document.getElementById('txtGroup4Email').value != '')
    {
    iMultiplier=5;
    }
    if(document.getElementById('txtGroup5Firstname').value != '' || document.getElementById('txtGroup5Surname').value != '' || document.getElementById('txtGroup5Email').value != '')
    {
     iMultiplier=6;
    }
    document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) * iMultiplier).toFixed(2) + ' (inc group members)';
    }

    It is fired from an onblur event in the div below once the chkbox is ticked, the link to the page is https://www.doitforcharity.com/book-...eid=1990&cid=0 but you may need to progress through https://www.doitforcharity.com/book-....aspx?eid=1990 first:


    Code:
     
    <div id="pnlGroupBooking">
    <label class="boldfieldlabel" for="chkGroupBooking">Do you wish to book for others too? </label>
    <input id="chkGroupBooking" type="checkbox" language="javascript" onclick="__doPostBack('chkGroupBooking','')" checked="checked" name="chkGroupBooking">
    (you may book up to 5 additional people)
    <div id="pnlGroupBookingNames" style="border: 1px solid LightGrey; width: 500px;" styles="padding:10px;">
    <strong>Group Member Names</strong>
    <br>
    <p>
    </p>
    <p>
    </p>
    <p style="vertical-align: top;">
    <strong>1) </strong>
    <input id="txtGroup1Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup1Firstname">
    <input id="txtGroup1Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup1Surname">
    <input id="txtGroup1Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup1Email">
    <br>
    <strong>2) </strong>
    <input id="txtGroup2Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup2Firstname">
    <input id="txtGroup2Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup2Surname">
    <input id="txtGroup2Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup2Email">
    <br>
    <strong>3) </strong>
    <input id="txtGroup3Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup3Firstname">
    <input id="txtGroup3Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup3Surname">
    <input id="txtGroup3Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup3Email">
    <br>
    <strong>4) </strong>
    <input id="txtGroup4Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup4Firstname">
    <input id="txtGroup4Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup4Surname">
    <input id="txtGroup4Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup4Email">
    <br>
    <strong>5) </strong>
    <input id="txtGroup5Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup5Firstname">
    <input id="txtGroup5Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup5Surname">
    <input id="txtGroup5Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup5Email">
    </p>
    </div>
    </div>
    Thanks!
    Last edited by longstuff; 12-15-2011 at 07:37 PM. Reason: more detail needed

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Have you tried using your error console or Firebug? That would expose the problem.

    Firefox does not support the innerText property. Instead, it supports the textContent property.
    http://blog.coderlab.us/2005/09/22/u...-with-firefox/

    Or use innerHTML if the elements are spans or divs as opposed to textboxes or textareas

    I see no elements named "cost" and "totalcost".

    if(document.getElementById('txtGroup1Firstname').value != ''
    Be aware that single space or a ? will pass the validation.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 12-15-2011 at 04:47 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    longstuff (12-15-2011)

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi, I have installed firebug but it's not really helping me find the problem which I presume is down to me not knowing how to use it properly or debug JS properly!

    I understand that if(document.getElementById('txtGroup1Firstname').value != '' will validate with anything, which is fine for the moment.

    Thanks

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    See my revised post #2. But you make it hard to test when you do not include all the code.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    So Firebug is telling me that the var iMultiplier is undefined, how do I go about defining it?

    I assumed that
    Code:
    {
    iMultipler=x;
    }
    Was the definition in the script?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    The problem is innerText as I say.

    There is no need to use both Number and parseFloat.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    longstuff (12-15-2011)

  • #7
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Sorry, I thought I was including all the code! I think I have now added the element with cost and totalcost to my original posting and used the correct code tags for you.

    Thank you for the link, I'll look into innerTEXT/HTML etc.

    Cheers!

  • #8
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes! textContent did it! Amazing, so simple. Thank you so much!!


  •  

    Tags for this Thread

    Posting Permissions

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