Hello,
Being a newbie, please forgive me ahead of time for asking what may be a simplistic question. I have a form that I error check using onBlur to call a routine, and the routine works well in IE 6 but when I try it in Netscape 7 it doesn't work as I think it should.
What I want to do is check the entry and if it isn't valid, select the same form field and give focus back so user can make correction. If it is OK, then add the total entered to the grand total and display. The main thrust being that I want the script to calculate totals rather than the user. In Netscape what happens is focus is given to field clicked after entry is made and total isn't updated. I will display the code below. Are there any basic differences between the browsers' use of javascript or is there an article someonde can point me too?
Notes:
Form name is EducationReg
All in a table with 5 columns
Repeat html input code 10 times so up to ten different lines on form
I'm not saying this is best or most efficient way to do what I want but it does work (at least in ie)
I hope this is enough info. If I left something out let me know. TIA
ChrisH
note: The smileys are supposed to be colons after looking at preview
HTML INPUT CODE:
<tr>
<td align="right" valign="top" width="25%"><font color="#FF0000">*</font> Teacher: </td>
<td valign="top" width="28%"><input type="text" title="Please enter the teacher's name." size="30" name="teacher1" maxlength="40" tabindex="3" value="" onblur="Check_class(this)" style="border-left: 2px solid #808080; border-top: 2px solid #808080" /></td>
<td align="right" valign="top" width="15%">Class #: </td>
<td align="left" valign="top" width="5%"><input type="text" title="Enter class name if applicable." name="Class1" maxlength="40" size="2" tabindex="4" style="border-left: 2px solid #808080; border-top: 2px solid #808080" /></td>
<td align="right" valign="top" width="22%"><font color="#FF0000">*</font> # of students:
<input type="text" title="Enter tentative # of students in class as of September 2004." size="2" name="kids1" maxlength="2" tabindex="5" value="" onBlur="Check_num(this.value,this,EducationReg.teacher1)" style="border-left: 2px solid #808080; border-top: 2px solid #808080"/>
</td>
</tr>
HTML code for display
<tr>
<td align="right" colspan="5" valign="top">Tentative # of
Students:
<input type="text" title="This total will be automatically calculated" size="4" name="total_kids" maxlength="0" value="0" onFocus="JavaScript
under_six.select())" style="border-left: 2px solid #808080; border-top: 2px solid #808080"/></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top"> </td>
</tr>
<tr>
<td align="right" colspan="5" valign="top"><b>Subtract Tentative # of Students 5 and under:</b>
<input type="text" title="Enter estimated # of students 5 years of age and under. If none, just leave the number at zero." size="4" name="under_six" maxlength="3" tabindex="33" value="0" style="background-color: #FFFFCC" onblur="Check_chap(this.value,this)" /></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative # of Paying Students:
<input type="text" title="This total will be automatically calculated" size="4" name="paid_kids" maxlength="0" value="0" onFocus="JavaScript
chaperone.select())" style="border-left: 2px solid #808080; border-top: 2px solid #808080"/></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative # of
Teachers:
<input type="text" title="This total will be automatically calculated" size="4" name="teachers" maxlength="0" value="0" style="background-color: #FFFFCC" onFocus="JavaScript
chaperone.select())" /></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top"><b>Tentative # of
Chaperones:</b>
<input type="text" title="Enter the estimated # of chaperones accompanying the group(s)" size="4" name="chaperone" maxlength="2" tabindex="34" value="0" onblur="Check_chap(this.value,this)" style="border-left: 2px solid #808080; border-top: 2px solid #808080" /></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative # of Paying Attendees:
<input type="text" title="This total will be automatically calculated. It does not include ages 5 and under." size="4" name="total_people" maxlength="0" value="0" style="background-color: #FFFFCC" onFocus="JavaScript
buses.select())" /></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative Total cost
@ $6/person = $
<input type="text" title="This amount will be automatically calculated" size="4" name="total_cost" maxlength="0" value="0" onFocus="JavaScript
buses.select())" style="border-left: 2px solid #808080; border-top: 2px solid #808080"/></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top"><font color="#FF0000">Note: To confirm registration send in ---> Less Deposit required @ $30/class = $</font>
<input type="text" title="This amount will be automatically calculated" size="4" name="deposit_total" maxlength="0" value="0" style="background-color: #FFFFCC" onFocus="JavaScript
buses.select())" /></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative Balance due = $
<input type="text" title="This amount will be automatically calculated" size="4" name="balance" maxlength="0" value="0" onFocus="JavaScript
buses.select())" style="border-left: 2px solid #808080; border-top: 2px solid #808080"/></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top"><b>Tentative
# of Buses:</b>
<input type="text" title="Enter the estimated # number of buses required to bring the group(s)" size="4" name="buses" maxlength="2" tabindex="35" value="0" style="background-color: #FFFFCC" onblur="Check_chap(this.value,this)" /></td>
</tr>
Javascript code:
function Check_num(number2chk,var_name,teach_name)
{
if (Checker(number2chk)==false)
{// if both teacher field and student # field are empty it's OK
if ((teach_name.value=='') && (var_name.value==''))
{
Display_kids.call()
return
}
alert("The number of students you entered is not valid. Please enter an Integer between 1 and 99. If you don't want an entry here, first be sure corresponding teacher name has no entry and then number has no entry. The cursor will now appear at the erroneous entry point.")
var_name.select()
var_name.focus()
return
}
else
{
Display_kids.call()
return
}
}
function Checker(numb2chk)
{
var Count=0
var test = numb2chk.substring(Count,Count+1)
if (test.match(/^[0-9]+$/)||test=="" ||test==" ")
{
var test1=test
}
else
{
return false
}
Count=Count+1
test = numb2chk.substring(Count,Count+1)
if (test.match(/^[0-9]+$/)||test=="" ||test==" ")
{// this checks if both digits are blanks or zeroes
if ((test1==""||test1==" " ||test1=="0")&& test==""||test==" "||test=="0"))
{
return false
}
else
{
return true
}
}
else
{
return false
}
}
function Check_chap(test_num,test_name)
{
if (Checker(test_num)==false)
{// Check if both digits are zero or blanks. If they are set value to zero.
if (test_name.value==''|| test_name.value==' ' || test_name.value=='0' ||test_name.value=='00' ||test_name.value==' 0' ||test_name.value=='0'||test_name.value=='0 '||test_name.value==' ')
{
test_name.value='0'
Display.call()
return
}
else
{
alert("The number you entered is not valid. Please enter an Integer between 0 and 99. The cursor will now appear at the erroneous entry point.")
}
test_name.select()
test_name.focus()
return
}
else
{
test_name.value=parseInt(test_name.value,10)
Display.call()
return
}
}
function Display_kids()
{
var total = new Array(10)
total[0]=document.EducationReg.kids1.value
total[1]=document.EducationReg.kids2.value
total[2]=document.EducationReg.kids3.value
total[3]=document.EducationReg.kids4.value
total[4]=document.EducationReg.kids5.value
total[5]=document.EducationReg.kids6.value
total[6]=document.EducationReg.kids7.value
total[7]=document.EducationReg.kids8.value
total[8]=document.EducationReg.kids9.value
total[9]=document.EducationReg.kids10.value
for (x=0; x<10; x++)
{
if (total[x]=='')
{
total_number = total_number + 0
}
else
{
total_number=total_number+parseInt(total[x],10)
}
}
document.EducationReg.total_kids.value=total_number
Display.call()
return
}
function Display()
{
document.EducationReg.deposit_total.value=parseInt(document.EducationReg.teachers.value,10)*30
document.EducationReg.paid_kids.value=(parseInt(document.EducationReg.total_kids.value,10)-parseInt(document.EducationReg.under_six.value,10))
document.EducationReg.total_people.value=(parseInt(document.EducationReg.paid_kids.value,10)+parseIn t(document.EducationReg.teachers.value,10)+parseInt(EducationReg.chaperone.value,10))
document.EducationReg.total_cost.value=document.EducationReg.total_people.value*6
document.EducationReg.balance.value=document.EducationReg.total_cost.value-document.EducationReg.deposit_total.value
return
}
function Check_class(teacher)
{
if (teacher.value=='')
{
Display_class.call()
return
}
else
{ //the field isn't empty but may be all spaces. This will check to see
for (count=0;count<teacher.value.length;count++)
{
if (teacher.value.substring(count,count+1)==' ')
{ //just keep looping to see if next character is a space
}
else
{ //If there are leading spaces before first character, this will strip them off and then display new value
teacher.value=teacher.value.substring(count,teacher.value.length)
Display_class.call()
return
}
}
teacher.value=''
Display_class.call()
}
}
function Display_class()
{
number_classes = 0
var classes = new Array(10)
classes[0]=EducationReg.teacher1.value
classes[1]=EducationReg.teacher2.value
classes[2]=EducationReg.teacher3.value
classes[3]=EducationReg.teacher4.value
classes[4]=EducationReg.teacher5.value
classes[5]=EducationReg.teacher6.value
classes[6]=EducationReg.teacher7.value
classes[7]=EducationReg.teacher8.value
classes[8]=EducationReg.teacher9.value
classes[9]=EducationReg.teacher10.value
for (x=0; x<10; x++)
{
if (classes[x]=='')
{
number_classes = number_classes + 0
}
else
{
number_classes = number_classes+ 1
}
}
EducationReg.teachers.value=number_classes
Display.call()
return
}
Being a newbie, please forgive me ahead of time for asking what may be a simplistic question. I have a form that I error check using onBlur to call a routine, and the routine works well in IE 6 but when I try it in Netscape 7 it doesn't work as I think it should.
What I want to do is check the entry and if it isn't valid, select the same form field and give focus back so user can make correction. If it is OK, then add the total entered to the grand total and display. The main thrust being that I want the script to calculate totals rather than the user. In Netscape what happens is focus is given to field clicked after entry is made and total isn't updated. I will display the code below. Are there any basic differences between the browsers' use of javascript or is there an article someonde can point me too?
Notes:
Form name is EducationReg
All in a table with 5 columns
Repeat html input code 10 times so up to ten different lines on form
I'm not saying this is best or most efficient way to do what I want but it does work (at least in ie)
I hope this is enough info. If I left something out let me know. TIA
ChrisH
note: The smileys are supposed to be colons after looking at preview
HTML INPUT CODE:
<tr>
<td align="right" valign="top" width="25%"><font color="#FF0000">*</font> Teacher: </td>
<td valign="top" width="28%"><input type="text" title="Please enter the teacher's name." size="30" name="teacher1" maxlength="40" tabindex="3" value="" onblur="Check_class(this)" style="border-left: 2px solid #808080; border-top: 2px solid #808080" /></td>
<td align="right" valign="top" width="15%">Class #: </td>
<td align="left" valign="top" width="5%"><input type="text" title="Enter class name if applicable." name="Class1" maxlength="40" size="2" tabindex="4" style="border-left: 2px solid #808080; border-top: 2px solid #808080" /></td>
<td align="right" valign="top" width="22%"><font color="#FF0000">*</font> # of students:
<input type="text" title="Enter tentative # of students in class as of September 2004." size="2" name="kids1" maxlength="2" tabindex="5" value="" onBlur="Check_num(this.value,this,EducationReg.teacher1)" style="border-left: 2px solid #808080; border-top: 2px solid #808080"/>
</td>
</tr>
HTML code for display
<tr>
<td align="right" colspan="5" valign="top">Tentative # of
Students:
<input type="text" title="This total will be automatically calculated" size="4" name="total_kids" maxlength="0" value="0" onFocus="JavaScript

</tr>
<tr>
<td align="right" colspan="5" valign="top"> </td>
</tr>
<tr>
<td align="right" colspan="5" valign="top"><b>Subtract Tentative # of Students 5 and under:</b>
<input type="text" title="Enter estimated # of students 5 years of age and under. If none, just leave the number at zero." size="4" name="under_six" maxlength="3" tabindex="33" value="0" style="background-color: #FFFFCC" onblur="Check_chap(this.value,this)" /></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative # of Paying Students:
<input type="text" title="This total will be automatically calculated" size="4" name="paid_kids" maxlength="0" value="0" onFocus="JavaScript

</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative # of
Teachers:
<input type="text" title="This total will be automatically calculated" size="4" name="teachers" maxlength="0" value="0" style="background-color: #FFFFCC" onFocus="JavaScript

</tr>
<tr>
<td align="right" colspan="5" valign="top"><b>Tentative # of
Chaperones:</b>
<input type="text" title="Enter the estimated # of chaperones accompanying the group(s)" size="4" name="chaperone" maxlength="2" tabindex="34" value="0" onblur="Check_chap(this.value,this)" style="border-left: 2px solid #808080; border-top: 2px solid #808080" /></td>
</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative # of Paying Attendees:
<input type="text" title="This total will be automatically calculated. It does not include ages 5 and under." size="4" name="total_people" maxlength="0" value="0" style="background-color: #FFFFCC" onFocus="JavaScript

</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative Total cost
@ $6/person = $
<input type="text" title="This amount will be automatically calculated" size="4" name="total_cost" maxlength="0" value="0" onFocus="JavaScript

</tr>
<tr>
<td align="right" colspan="5" valign="top"><font color="#FF0000">Note: To confirm registration send in ---> Less Deposit required @ $30/class = $</font>
<input type="text" title="This amount will be automatically calculated" size="4" name="deposit_total" maxlength="0" value="0" style="background-color: #FFFFCC" onFocus="JavaScript

</tr>
<tr>
<td align="right" colspan="5" valign="top">Tentative Balance due = $
<input type="text" title="This amount will be automatically calculated" size="4" name="balance" maxlength="0" value="0" onFocus="JavaScript

</tr>
<tr>
<td align="right" colspan="5" valign="top"><b>Tentative
# of Buses:</b>
<input type="text" title="Enter the estimated # number of buses required to bring the group(s)" size="4" name="buses" maxlength="2" tabindex="35" value="0" style="background-color: #FFFFCC" onblur="Check_chap(this.value,this)" /></td>
</tr>
Javascript code:
function Check_num(number2chk,var_name,teach_name)
{
if (Checker(number2chk)==false)
{// if both teacher field and student # field are empty it's OK
if ((teach_name.value=='') && (var_name.value==''))
{
Display_kids.call()
return
}
alert("The number of students you entered is not valid. Please enter an Integer between 1 and 99. If you don't want an entry here, first be sure corresponding teacher name has no entry and then number has no entry. The cursor will now appear at the erroneous entry point.")
var_name.select()
var_name.focus()
return
}
else
{
Display_kids.call()
return
}
}
function Checker(numb2chk)
{
var Count=0
var test = numb2chk.substring(Count,Count+1)
if (test.match(/^[0-9]+$/)||test=="" ||test==" ")
{
var test1=test
}
else
{
return false
}
Count=Count+1
test = numb2chk.substring(Count,Count+1)
if (test.match(/^[0-9]+$/)||test=="" ||test==" ")
{// this checks if both digits are blanks or zeroes
if ((test1==""||test1==" " ||test1=="0")&& test==""||test==" "||test=="0"))
{
return false
}
else
{
return true
}
}
else
{
return false
}
}
function Check_chap(test_num,test_name)
{
if (Checker(test_num)==false)
{// Check if both digits are zero or blanks. If they are set value to zero.
if (test_name.value==''|| test_name.value==' ' || test_name.value=='0' ||test_name.value=='00' ||test_name.value==' 0' ||test_name.value=='0'||test_name.value=='0 '||test_name.value==' ')
{
test_name.value='0'
Display.call()
return
}
else
{
alert("The number you entered is not valid. Please enter an Integer between 0 and 99. The cursor will now appear at the erroneous entry point.")
}
test_name.select()
test_name.focus()
return
}
else
{
test_name.value=parseInt(test_name.value,10)
Display.call()
return
}
}
function Display_kids()
{
var total = new Array(10)
total[0]=document.EducationReg.kids1.value
total[1]=document.EducationReg.kids2.value
total[2]=document.EducationReg.kids3.value
total[3]=document.EducationReg.kids4.value
total[4]=document.EducationReg.kids5.value
total[5]=document.EducationReg.kids6.value
total[6]=document.EducationReg.kids7.value
total[7]=document.EducationReg.kids8.value
total[8]=document.EducationReg.kids9.value
total[9]=document.EducationReg.kids10.value
for (x=0; x<10; x++)
{
if (total[x]=='')
{
total_number = total_number + 0
}
else
{
total_number=total_number+parseInt(total[x],10)
}
}
document.EducationReg.total_kids.value=total_number
Display.call()
return
}
function Display()
{
document.EducationReg.deposit_total.value=parseInt(document.EducationReg.teachers.value,10)*30
document.EducationReg.paid_kids.value=(parseInt(document.EducationReg.total_kids.value,10)-parseInt(document.EducationReg.under_six.value,10))
document.EducationReg.total_people.value=(parseInt(document.EducationReg.paid_kids.value,10)+parseIn t(document.EducationReg.teachers.value,10)+parseInt(EducationReg.chaperone.value,10))
document.EducationReg.total_cost.value=document.EducationReg.total_people.value*6
document.EducationReg.balance.value=document.EducationReg.total_cost.value-document.EducationReg.deposit_total.value
return
}
function Check_class(teacher)
{
if (teacher.value=='')
{
Display_class.call()
return
}
else
{ //the field isn't empty but may be all spaces. This will check to see
for (count=0;count<teacher.value.length;count++)
{
if (teacher.value.substring(count,count+1)==' ')
{ //just keep looping to see if next character is a space
}
else
{ //If there are leading spaces before first character, this will strip them off and then display new value
teacher.value=teacher.value.substring(count,teacher.value.length)
Display_class.call()
return
}
}
teacher.value=''
Display_class.call()
}
}
function Display_class()
{
number_classes = 0
var classes = new Array(10)
classes[0]=EducationReg.teacher1.value
classes[1]=EducationReg.teacher2.value
classes[2]=EducationReg.teacher3.value
classes[3]=EducationReg.teacher4.value
classes[4]=EducationReg.teacher5.value
classes[5]=EducationReg.teacher6.value
classes[6]=EducationReg.teacher7.value
classes[7]=EducationReg.teacher8.value
classes[8]=EducationReg.teacher9.value
classes[9]=EducationReg.teacher10.value
for (x=0; x<10; x++)
{
if (classes[x]=='')
{
number_classes = number_classes + 0
}
else
{
number_classes = number_classes+ 1
}
}
EducationReg.teachers.value=number_classes
Display.call()
return
}
Comment