Form not working with Safari JS error?

cjmicro 30 Jan, 2009
The form we designed is working fine in IE 7 but not other browsers. From some research it seems that some browsers (Safari etc) will not parse the js correctly if there are any errors, like missing ; or ) etc... while some browsers will just ignore that.

I wonder if anyone could look at the script and tell me if there are glaring errors that could be causing this... or if you have any other ideas?

Note that it caclulates classes & rates of those classes for up to 4 children. The part that does not seem to be working is where it takes the class info & child name to the summary tab. It does pull over the child subototal but not the child name or class descriptions.

Here is a link to the form. You just have to check a class from the child1 tab then go to summary to see what I mean. It works as planned in IE...just not other browsers.
http://www.colvinrunpto.org/index.php?option=com_chronocontact&chronoformname=cheryl

Here is the js code from the form code area.


function CalcFinalTotal(totalfield){
var Total = 0.0;
var i = 0;
var idstr;


for (i = 1; i <= 4; i++)
{
  idstr = "TChild" + i;  

  Total += parseFloat(document.getElementById(idstr).value);
  
}
totalfield.value = Total;
document.getElementById("x_amount").value = Total;

}
function CalcTotal1(btncount, field1, field2, tfield){
var Total = 0.0;
var i = 0;
var idstr;
var summarystr = "";
var hiddenidstr;
var gradeidstr;
var dtidstr;
var locidstr;

for (i = 1; i <= btncount; i++)
{
  idstr = "button1_" + i;  
  hiddenidstr = "cost1_" + i;  
  gradeidstr = "grade1_" + i; 
  dtidstr = "daytime1_" + i; 
  locidstr = "locat1_" + i; 

  if (document.getElementById(idstr).checked)
  { 
	Total += parseFloat(document.getElementById(hiddenidstr).value);
    summarystr += "[";
    summarystr += document.getElementById(idstr).name;
    summarystr += ", ";
    summarystr += document.getElementById(gradeidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(dtidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(locidstr).value;
    summarystr += "] \r\n";
  }
}
field1.value = Total;
field2.value = Total;
CalcFinalTotal(tfield);
document.getElementById("Child1Name").value = document.getElementById("Child1").value;
document.getElementById("ClassSummary1").value = summarystr;

}

function Child1NameChange()
{
document.getElementById("Child1Name").value = document.getElementById("Child1").value;
}

function Child2NameChange()
{
document.getElementById("Child2Name").value = document.getElementById("Child2").value;
}

function Child3NameChange()
{
document.getElementById("Child3Name").value = document.getElementById("Child3").value;
}

function Child4NameChange()
{
document.getElementById("Child4Name").value = document.getElementById("Child4").value;
}

function CalcTotal2(btncount, field1, field2, tfield){
var Total = 0.0;
var i = 0;
var idstr;
var summarystr = "";
var hiddenidstr;
var gradeidstr;
var dtidstr;
var locidstr;

for (i = 1; i <= btncount; i++)
{
  idstr = "button2_" + i;  
  hiddenidstr = "cost2_" + i;  
  gradeidstr = "grade2_" + i; 
  dtidstr = "daytime2_" + i; 
  locidstr = "locat2_" + i; 

  if (document.getElementById(idstr).checked)
  { 
	Total += parseFloat(document.getElementById(hiddenidstr).value);
    summarystr += "[";
    summarystr += document.getElementById(idstr).name;
    summarystr += ", ";
    summarystr += document.getElementById(gradeidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(dtidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(locidstr).value;
    summarystr += "] \r\n";
  }
}
field1.value = Total;
field2.value = Total;
CalcFinalTotal(tfield);
document.getElementById("Child2Name").value = document.getElementById("Child2").value;
document.getElementById("ClassSummary2").value = summarystr;
}

function CalcTotal3(btncount, field1, field2, tfield){
var Total = 0.0;
var i = 0;
var idstr;
var summarystr = "";
var hiddenidstr;
var gradeidstr;
var dtidstr;
var locidstr;

for (i = 1; i <= btncount; i++)
{
  idstr = "button3_" + i;  
  hiddenidstr = "cost3_" + i;  
  gradeidstr = "grade3_" + i; 
  dtidstr = "daytime3_" + i; 
  locidstr = "locat3_" + i; 

  if (document.getElementById(idstr).checked)
  { 
	Total += parseFloat(document.getElementById(hiddenidstr).value);
    summarystr += "[";
    summarystr += document.getElementById(idstr).name;
    summarystr += ", ";
    summarystr += document.getElementById(gradeidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(dtidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(locidstr).value;
    summarystr += "] \r\n";
  }
}
field1.value = Total;
field2.value = Total;
CalcFinalTotal(tfield);
document.getElementById("Child3Name").value = document.getElementById("Child3").value;
document.getElementById("ClassSummary3").value = summarystr;
}

function CalcTotal4(btncount, field1, field2, tfield){
var Total = 0.0;
var i = 0;
var idstr;
var summarystr = "";
var hiddenidstr;
var gradeidstr;
var dtidstr;
var locidstr;

for (i = 1; i <= btncount; i++)
{
  idstr = "button4_" + i;  
  hiddenidstr = "cost4_" + i;  
  gradeidstr = "grade4_" + i; 
  dtidstr = "daytime4_" + i; 
  locidstr = "locat4_" + i; 

  if (document.getElementById(idstr).checked)
  { 
	Total += parseFloat(document.getElementById(hiddenidstr).value);
    summarystr += "[";
    summarystr += document.getElementById(idstr).name;
    summarystr += ", ";
    summarystr += document.getElementById(gradeidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(dtidstr).value;
    summarystr += ", ";
    summarystr += document.getElementById(locidstr).value;
    summarystr += "] \r\n";
  }
}
field1.value = Total;
field2.value = Total;
CalcFinalTotal(tfield);
document.getElementById("Child4Name").value = document.getElementById("Child4").value;
document.getElementById("ClassSummary4").value = summarystr;
}



function transferBillingData()
{
document.getElementById("x_first_name").value = document.getElementById("firstname").value;
document.getElementById("x_last_name").value = document.getElementById("lastname").value;
document.getElementById("x_email").value = document.getElementById("email").value;
document.getElementById("x_address").value = document.getElementById("address").value;
document.getElementById("x_city").value = document.getElementById("city").value;
document.getElementById("x_state").value = document.getElementById("state").value;
document.getElementById("x_zip").value = document.getElementById("zipcode").value;
document.getElementById("x_phone").value = document.getElementById("phone").value;


}



I know this is long but I hope someone can take the time to look and see if there are some glaring js error that you can easily find.

Once this thing is working right (which at this point looks like never...😢 ) I will post it as an example.

Thanks for any assistance. I know it's a lot to ask but I am desperate. 😢 😢

Cheryl
GreyHead 30 Jan, 2009
Hi cheryl,

Quick answer - there's no 'id' in
<input type="text" name="TChild1" size="20" value="0" readonly="readonly" >
longer answer later

Bob
cjmicro 30 Jan, 2009
Thanks Bob, will let you know if the short answer does it. LOL
Cheryl
cjmicro 30 Jan, 2009
I don't think that fixes it. Any other ideas? Let me know, thanks.

Any particular doctype that would help with this type of problem? I have tried a few and can't seem to get that to make much difference either.

Cheryl
GreyHead 30 Jan, 2009
Hi Cheryl,

Can you take a form backup and email to me.

Bob
cjmicro 30 Jan, 2009
No, you were right, it's ok (must have missed one on the first fixing round :-)

Just got it working in all browsers and all is good. THANK YOU THANK YOU THANK YOU.

Cheryl
GreyHead 30 Jan, 2009
Hi Cheryl,

Sorry - I was on a long phone call and could only type the short answer. I've just seen you've fixed it but will still post the longer answer as I've written it.

I think that the CalcFinalTotal function breaks down in this loop
for (i = 1; i <= 4; i++) {
  idstr = "TChild" + i;
  Total += parseFloat(document.getElementById(idstr).value);
}
because there is no Element with an id='Tchild1' Then it doesn't return to the CalcTotal1() function to complete writing the strings into the input and textarea.

Bob
cjmicro 31 Jan, 2009
Thanks Bob, I just have to make the tab navigation go to the top of the next tab and we are golden. ;-)

I know you and Max both gave me ideas on this so I will go back and look. Thanks again!!!

Cheryl
This topic is locked and no more replies can be posted.