Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript works in Firefox and not IE7, again!
Old 02-26-2008, 11:00 PM Javascript works in Firefox and not IE7, again!
Novice Talker

Posts: 14
Name: Orion Tiller
Trades: 0
I have a new bit of code that works for me in firefox but not in IE7. Can someone see my problem?

You can see the html here:

http://www.mortgagequoteshere.com/



Here is the javascript:

PHP Code:
function validate(form) {
 var 
valid true;
 var 
FirstErrorField '';
 
//var checkboxes = new Array();
 
var thisbox '';
 
 for(var 
0form.elements.lengthi++ ) {
  
//alert( i );
  
try{
    if(
form.elements[i].type != "hidden") {
    
//if(form.elements[i].parentNode.parentNode.parentNode.getElementsByTagName("div")[1].getElementsByTagName("label")[0].getAttribute("class") == "required") {
    
if(form.elements[i].getAttribute("class") == "required") {
     if(
form.elements[i].value == '') {
      
highlightField(form.elements[i]);
      
valid false;
     } 
     else if( 
form.elements[i].getAttribute("title") == "numeric" ) {
      if ( (
isNumeric(form.elements[i].value) == false) || ( form.elements[i].value.length form.elements[i].getAttribute("maxLength") ) ) {
       
highlightField(form.elements[i]);
       
valid false;
      }
      else {
       
normalField(form.elements[i]);
      }
     }
     else if( 
form.elements[i].getAttribute("name") == "EMAIL" ) {
      if ( 
validateAddress(form.elements[i].value) == false ) {
       
highlightField(form.elements[i]);
       
valid false;
      }
      else {
       
normalField(form.elements[i]);
      }
     }
     else {
      
normalField(form.elements[i]);
     }
    }
   }
  } 
  catch( 
error ) {
  }
 }
 
 if( 
valid == false ) {
  
alert"Please fill in all required form fields with valid data." );
 } 
 return 
valid;
}
function 
highlightField(field) {
  
field.style.backgroundColor '#FF6666';
  
field.style.color 'white';
}
function 
normalField(field) {
  
field.style.backgroundColor 'window';
  
field.style.color 'windowtext';
}
function 
validateAddress(incoming) {
 var 
emailstring incoming;
 var 
ampIndex emailstring.indexOf("@");
 var 
afterAmp emailstring.substring((ampIndex 1), emailstring.length);
  
// find a dot in the portion of the string after the ampersand only
 
var dotIndex afterAmp.indexOf(".");
  
// determine dot position in entire string (not just after amp portion)
 
dotIndex dotIndex ampIndex 1;
  
// afterAmp will be portion of string from ampersand to dot
 
afterAmp emailstring.substring((ampIndex 1), dotIndex);
  
// afterDot will be portion of string from dot to end of string
 
var afterDot emailstring.substring((dotIndex 1), emailstring.length);
 var 
beforeAmp emailstring.substring(0,(ampIndex));
 var 
email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
  // index of -1 means "not found"
 
if ((emailstring.indexOf("@") != "-1") &&
  (
emailstring.length 5) &&
  (
afterAmp.length 0) &&
  (
beforeAmp.length 1) &&
  (
afterDot.length 1) &&
  (
email_regex.test(emailstring)) ) {
    return 
true;
 } else {
  return 
false;
 }

function 
isNumeric(sText) {
   var 
ValidChars "0123456789.";
   var 
IsNumber=true;
   var 
Char;
 
   for (var 
0sText.length && IsNumber == truei++) 
      { 
      
Char sText.charAt(i); 
      if (
ValidChars.indexOf(Char) == -1
         {
         
IsNumber false;
         }
      }
   return 
IsNumber;
 
 } 
otiller is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-27-2008, 01:23 AM Re: Javascript works in Firefox and not IE7, again!
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Take out the try/catch (error) parts. Then an error can be generated and we can see it to figure it out. Or come up with some error trapping so we can see the error.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-27-2008, 01:24 AM Re: Javascript works in Firefox and not IE7, again!
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Oh...and I just noticed this. Change your form name to something other than form. I've seen IE throw up on submit buttons named submit, so change form to something like "MortgageForm".
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-27-2008, 01:27 AM Re: Javascript works in Firefox and not IE7, again!
Novice Talker

Posts: 14
Name: Orion Tiller
Trades: 0
got rid of the try catch and changed the form name
otiller is offline
Reply With Quote
View Public Profile
 
Old 02-27-2008, 01:31 AM Re: Javascript works in Firefox and not IE7, again!
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Change it in the JS, too. I'm thinking that it may be throwing things off there (call it theForm).

At any rate, it's not throwing an error, which suggests that it's not firing the validate function at all.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-27-2008, 01:37 AM Re: Javascript works in Firefox and not IE7, again!
Novice Talker

Posts: 14
Name: Orion Tiller
Trades: 0
I changed it but still not generating errors.

HTML Code:
  <script language="javascript" type="text/javascript" src="validate.js"></script>
                        <form name="mortgageform" method="post" action="index.php" onsubmit="return validate(this);">
otiller is offline
Reply With Quote
View Public Profile
 
Old 02-27-2008, 01:58 AM Re: Javascript works in Firefox and not IE7, again!
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I think I might see why now. I haven't tried this before myself, but I'm thinking your problem might be the image submit button.

1) Try changing it to a normal submit button (just for testing purposes). If it submits, then your problem's there.

2) If 1) works, you'll pretty well have to stick with it.

Personally, I don't get why you're not using PHP validation for this form (unless this is stage 1). JS can be disabled; PHP can't.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-27-2008, 03:45 PM Re: Javascript works in Firefox and not IE7, again!
Novice Talker

Posts: 14
Name: Orion Tiller
Trades: 0
It still doesn't work with the submit button.

I just like the javascript validation, I can also add php validation and I probably will.
otiller is offline
Reply With Quote
View Public Profile
 
Old 02-27-2008, 06:08 PM Re: Javascript works in Firefox and not IE7, again!
Novice Talker

Posts: 14
Name: Orion Tiller
Trades: 0
Quote:
Originally Posted by ADAM Web Design View Post
Change it in the JS, too. I'm thinking that it may be throwing things off there (call it theForm).

At any rate, it's not throwing an error, which suggests that it's not firing the validate function at all.
So the validate function gets called but it's this expression that will evaluate in firefox but not in IE7. Any ideas why?

if(Theform.elements[i].getAttribute("class") == "required") {

otiller is offline
Reply With Quote
View Public Profile
 
Old 02-27-2008, 06:29 PM Re: Javascript works in Firefox and not IE7, again!
Novice Talker

Posts: 14
Name: Orion Tiller
Trades: 0
Yes the answer is:

if(Theform.elements[i].attributes['class'].value == "required") {
otiller is offline
Reply With Quote
View Public Profile
 
Old 02-27-2008, 07:15 PM Re: Javascript works in Firefox and not IE7, again!
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I didn't even see that part, but it makes sense.

At any rate, it looks like you got it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-27-2008, 07:33 PM Re: Javascript works in Firefox and not IE7, again!
Novice Talker

Posts: 14
Name: Orion Tiller
Trades: 0
ARGG!! Now it works in IE7 and not firefox. The validate function gets called and works and highlights the empty fields and returns false but the action still gets done now.


HTML Code:
  <script type="text/javascript" language="JavaScript" src="validate.js"></script>
                        <form name="mortgageform" method="POST" action="index.php" onsubmit="return validate(this);">
otiller is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 10:22 PM Re: Javascript works in Firefox and not IE7, again!
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by otiller View Post
Yes the answer is:

if(Theform.elements[i].attributes['class'].value == "required") {
There's also a snag with this, which is causing the Firefox failure. If no class attribute is applied .attributes['class'].value is undefined in FireFox and Opera, whereas in I.E. it's "". You probably have one or more elements with no class applied.

You need to check it's not undefined before reading it, or read Theform.elements[ i ].className whose default value is always "".
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript works in Firefox and not IE7, again!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.51588 seconds with 12 queries