Click to See Complete Forum and Search --> : Old JavaScript code messing things up?


Pete
03-28-2003, 01:47 PM
Hi, I've got some very old JavaScript code on a very important page that I think is messing up my Mac users... This is the code:

<script language="JavaScript1.2">

var testresults
function checkemail(){
var str=document.validation.semail.value
var filter=/^.+@.+\..{2,3}$/
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}
</script>

<script>
function checkbae(){
if (document.layers||document.all)
return checkemail()
else
return true
}
</script>

On occasion, I get a client that calls me and says, my email is name@domain.com and your page is showing me a pop-up.

Is there something wrong with the code by today's standards?

Thanks you kindly for the help,

Pete

FYI: 'semail' is the name of the form within the html for the email address. But I'm sure you folks figured that out just by looking at the code -- I'm such a newbie. ;)

angrytuna
03-28-2003, 02:05 PM
If I were you, I'd change your alert to:

else{
alert(document.validation.semail.value);
testresults=false
}

temporarily, to confirm what is being returned for your mac users. It's also worth noting that specifying language="JavaScript1.2" causes Netscape to behave in ways that are incompatible with the ECMA-262 standard.

Hope those help.

~at

Phil Karras
03-28-2003, 02:19 PM
One other minor point, which should NOT be the problem, is that the new standard uses the following script tag:
<script type='text/javascript'>

You might want to include that as in:

<script language="JavaScript" type='text/javascript'>

Pete
03-28-2003, 02:26 PM
WOW! The help around here is quick!

Ok, two questions:

Question 1:

So, I should change:

<script language="JavaScript1.2">

to:

<script language="JavaScript" type='text/javascript'>

Doing this won't mess anything up, correct?

Question 2:

I should change:

else{
alert("Please input a valid email address!")
testresults=false

to:

else{
alert(document.validation.semail.value);
testresults=false

I know I sound like a worried newbie -- and I am ;) -- but doing this also, won't mess aything up will it? This is being done to a live site.

Thanks for the help!! :-) :-) :-)

Pete

Phil Karras
03-28-2003, 02:50 PM
Question 1. - no

Question 2. - It will change the output in the alert statement to I think the value put in, not what I'd do. I'd do it your way, given them a warning, put the focus back on that field, & then return false.

else{
alert("Please input a valid email address!")
document.validation.semail.focus();
testresults=false
}

Last, messing things up is have the learning process.

Pete
03-28-2003, 02:58 PM
Ok...

So,

I'll implement "Question 1" now.

And just so I have it right.

I should change:

else{
alert("Please input a valid email address!")
testresults=false

to:

else{
alert("Please input a valid email address!")
document.validation.semail.focus();
testresults=false

Correct?

Now, just for my own learning... what have I done by making these changes that may make different browsers happy? I'm just wondering. :-)

Pete

Pete
03-28-2003, 03:01 PM
Opps...

One more thing...

should it be:

<script language="JavaScript" type='text/javascript'>
or should it be:

<script language="JavaScript" type="text/javascript">

Thanks again,
Pete

Phil Karras
03-28-2003, 03:05 PM
Now, just for my own learning... what have I done by making these changes that may make different browsers happy? I'm just wondering. :-)

If they are more strict then the script tag will keep them happy.

As to the other, not a thing in the world as far as I can see, it just makes it nicer.

?????????????????

<script language="JavaScript" type='text/javascript'>
or should it be:

<script language="JavaScript" type="text/javascript">

either is OK.

You ask too many questions before actually trying something so stop writing and screw something up so you can start learning!;)

Pete
03-28-2003, 03:12 PM
Ok. I changed both issues...

Tested on IE 6.0.28 and NS 7.0 -- everything seems to be good. Now I just sit and wait and see if anyone contacts me with the old problem.

Thanks for all the help!

I have to go do this on another form now! :)

Pete

Pete
03-28-2003, 03:19 PM
Here's the final version:

<script LANGUAGE="JavaScript" TYPE="text/javascript">

var testresults
function checkemail(){
var str=document.validation.semail.value
var filter=/^.+@.+\..{2,3}$/
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
document.validation.semail.focus();
testresults=false
}
return (testresults)
}
</script>

<script>
function checkbae(){
if (document.layers||document.all)
return checkemail()
else
return true
}
</script>

Hope this helps some lonely newb like me down the road. :-)

Pete

Phil Karras
03-29-2003, 10:22 AM
Very good, here's your checkemail() function re-written to make it shorter. Unless I've made a mistake this should do the same thing with fewer lines.

You should also learn to use the tags available on this forum so you can format code and things, generally it uses similar tags to HTML but instead of using < and > you use [ and ]. So, do display code use [ code ] (no spaces between [ & ] and the word code. Like this:

<script LANGUAGE="JavaScript" TYPE="text/javascript">

function checkemail() {
var str=document.validation.semail.value
var filter=/^.+@.+\..{2,3}$/;
var testresults = true;
if (!filter.test(str)) {
alert("Please input a valid email address!");
document.validation.semail.focus();
testresults=false;
}

return (testresults);
}
</script>

Now if you want BOLD you use [ b ], again no spaces. Oh, they also allow you to change colors with: [ color = blue ] - no spaces between anything.

I livens things up a bit. Don't forget to close the tags with the end tag, just like HTML but with [ & ], so for bold we get: [ /b ] (no spaces, and color we get: [ /color ], no spaces, etc.

Oh, one last thing. I've noticed that you do not use ; at the end of all JS statements. While this is strictly correct, JS does allow for the ; and you can then put more than one statement on a line. Generally I don't do that but I do ALWAYS use the ; because I program in way more than one language and all the others require it. So, it's a good habit to get in to. Just a thought.

Pete
03-31-2003, 05:25 AM
Thanks for the input. I'm not clear on what you mean by putting the ; at the end of each code. (I know in perl, I do it...) in any event, are you saying the correct way is to do or not to do it.

Sorry, just confused.

Thanks,

Pete