Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whyt a Java Script works in one browser but does not in another

Status
Not open for further replies.

dataplayer

Programmer
Jan 11, 2003
95
US
I have some Java Script functions used to work for both IE and Mozilla. After I moved them around, the program does not work in IE6.0 anymore, but still works with Mozilla browser. I spent almost one day for chasing this spooky cause of the problem. I still have no clue what went wrong.
These function are supposed to check the validation of the input entries. In Mozilla, they still perform normally, but in IE6.0, nothing was checked, nor is the program stopped when an invalid input was entered.

Can some one share some light. Thanks.

Frank
 
I had this car that worked just fine until I switched some parts around in it, and now it doesn't work anymore. What's wrong with my car?

Do you think that anybody could honestly answer that question?

Without giving us some sample source code or a link to your website there's no way any of us can help you. Your question was very vague and gives little to no detail.

-kaht

banghead.gif
 
dataplayer, its really hard to try and guess why the code stopped working. Can you post some of the code here so we can look at it and try to figure out what happened??

But if I had to guess, i'd say that your calling some methods, or using some syntaxes that some browsers do not support.

For example, IE supports document.getElementbyID but NS6- does not.

See what I mean??


____________________________________
Just Imagine.
 
Sure! It was a very lengthy program. Thanks for reading it.

The asp web page was written by DreamWeaver. I quote a part I think is causing the problem. The functions are all stored in a file called JSfunction.js. When the form is submitted, the JAVAScript functions are supposed to check all the required fields are entered, required radio buttons are checked, the date is entered in correct format, etc.

When I use Mozilla browser, the program works, but not for IE6.0


Web page part:

.
. (this part is omitted)
.
<html>
<head>
<title>The Collegium</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles/collegiumStyle.css" rel="stylesheet" type="text/css">
<script language="JavaScript1.2" >
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var isNN = (navigator.appName.indexOf("Netscape")!=-1);</script>
<script language="JavaScript1.2" src="JSfunctions.js"></script>
</head>
.
. (this part is omitted)
.
<form name="application1" method="post" action="addapp.asp" onSubmit="return validateForm(application1,document.application1.REQappDOB);">
.
. (this part is omitted)
.


Funcions part in JSfunctions.js file:

function validateForm(form,dateField) {
var form;
var i;
var dateField;
var required = 0;
var ct = form.elements.length;
var incompArr = new Array(1);
var elemArr = new Array(1);
var unfinCount = 0;
for(i=0; i<ct; i++) {
if(form.elements.name.substr(0,3) == "REQ") {
if((form.elements.type == "text" || form.elements.type == "password") && form.elements.value == "") {
incompArr[incompArr.length] = form.elements.name;
form.elements.style.backgroundColor = "#990000";
form.elements.style.color = "white";
unfinCount += 1;
}
if(form.elements.selectedIndex == 0) {
incompArr[incompArr.length] = form.elements.name;
form.elements.style.backgroundColor = "#990000";
form.elements.style.color = "white";
unfinCount += 1;
}
if(form.elements.type = "radio") {
if(checkRadioControl(form.elements.name)) {
radioCount += 1;
}
}
}
}
var msg;
var badForm = false;
if(unfinCount > 0) {
alert("Please fill in all required fields highlighted in red. ");
badForm = true;
}
if(form.REQappPassword.value != form.REQappPasswordVerify.value) {
alert("Your password fields do not match!")
badForm = true;
}
if(radioCount < 10 && radioCount >= 0) {
alert("Please check yes or no for each question.");
badForm = true;
}
if(checkDate(dateField) == false) {
badForm = true;
}
if(badForm == true) {
return false;
}
else { return true; }
}

function checkRadioControl(strFormField)
{
var objFormField = document.forms[0].elements[strFormField]
intControlLength = objFormField.length
var bolSelected = false;
for (i=0;i<intControlLength;i++){
if(objFormField.checked){
bolSelected = true;
break;
}
}
if(! bolSelected){
return false;
}
else{
return true;
}
}
function isInteger(s){
var i;
for (i = 0; i < s.length; i++){
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++){
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this = 31
if (i==4 || i==6 || i==9 || i==11) {this = 30}
if (i==2) {this = 29}
}
return this
}

function isDate(dtStr){
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strMonth=dtStr.substring(0,pos1)
var strDay=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert("The date format should be : mm/dd/yyyy")
return false
}
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
return false
}
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
}
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
}
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
return false
}
return true
}

function checkDate(date){
var dt=date
if (isDate(dt.value)==false){
dt.focus()
return false
}
return true
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form == input)index = i;
else i++;
return index;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top