Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2011, 03:58 PM   PM User | #1
longstuff
New to the CF scene

 
Join Date: Dec 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
longstuff is an unknown quantity at this point
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
longstuff is offline   Reply With Quote
Old 12-15-2011, 04:19 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 12-15-2011 at 04:47 PM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
longstuff (12-15-2011)
Old 12-15-2011, 04:30 PM   PM User | #3
longstuff
New to the CF scene

 
Join Date: Dec 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
longstuff is an unknown quantity at this point
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
longstuff is offline   Reply With Quote
Old 12-15-2011, 04:46 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 12-15-2011, 04:46 PM   PM User | #5
longstuff
New to the CF scene

 
Join Date: Dec 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
longstuff is an unknown quantity at this point
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?
longstuff is offline   Reply With Quote
Old 12-15-2011, 04:51 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
longstuff (12-15-2011)
Old 12-15-2011, 05:01 PM   PM User | #7
longstuff
New to the CF scene

 
Join Date: Dec 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
longstuff is an unknown quantity at this point
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!
longstuff is offline   Reply With Quote
Old 12-15-2011, 07:35 PM   PM User | #8
longstuff
New to the CF scene

 
Join Date: Dec 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
longstuff is an unknown quantity at this point
Yes! textContent did it! Amazing, so simple. Thank you so much!!
longstuff is offline   Reply With Quote
Reply

Bookmarks

Tags
errors, firefox, javascript, onblur

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:07 AM.


Advertisement
Log in to turn off these ads.