471,073 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

DW function, Firefox works, IE doesn't.

I would like to ask you the following:

I use Macromedia Dreamweaver as an editor for HTML and Js.

It also writes some js functions to simply validate forms.

I always used it with no bugs.

Till now. This is the problem (and the page):

================================================== =========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an
e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a
number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body>
<form name="formA">
<input type="text" name="pippo">
<input type="text" name="email">
<input name="A" type="submit"
onClick="MM_validateForm('pippo','','R','email','' ,'RisEmail');return
document.MM_returnValue" value="Invia">
</form>

<form name="formB">
<input type="hidden" name="pippo">
<input type="hidden" name="email">
</form>

</body>
</html>

================================================== =========================

My target is to validate "pippo" to have it not empty and "email" not
empty but also a valid email.

Dreamweaver wrote these 2 functions to do this and added onClick event
to button this way.

The only new thing I did is to write an hidden form with same fields
names because I have to do this before posting data.

I tried this code in Firefox and it works fine.

I tried this in IE and it says: "'val' is null or it is not an object".

What do you think about it?

Any help much appreciated.

Regards.

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #1
2 2018
Fabri <no@sp.am> wrote in message news:<31*************@individual.net>...
I would like to ask you the following:

I use Macromedia Dreamweaver as an editor for HTML and Js.

It also writes some js functions to simply validate forms.

I always used it with no bugs.

Till now. This is the problem (and the page):

================================================== =========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an
e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a
number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body>
<form name="formA">
<input type="text" name="pippo">
<input type="text" name="email">
<input name="A" type="submit"
onClick="MM_validateForm('pippo','','R','email','' ,'RisEmail');return
document.MM_returnValue" value="Invia">
</form>

<form name="formB">
<input type="hidden" name="pippo">
<input type="hidden" name="email">
</form>

</body>
</html>

================================================== =========================

My target is to validate "pippo" to have it not empty and "email" not
empty but also a valid email.

Dreamweaver wrote these 2 functions to do this and added onClick event
to button this way.

The only new thing I did is to write an hidden form with same fields
names because I have to do this before posting data.

I tried this code in Firefox and it works fine.

I tried this in IE and it says: "'val' is null or it is not an object".

What do you think about it?

Any help much appreciated.

Regards.


Well...you've got two pippos now so, you're up the creek. ;)

That MickeyMouse_findObj() routine isn't very good with same-named
form elements, which IE puts in an array (inside the document.all[]
array) so it can store pointers to both. Couldn't figure out any way
to pass that reference - pippo[0] - as a string argument, so the best
fix is probably to lose that function completely, and change this
line:

val=MM_findObj(args[i]);

....to

val=document.getElementById(args[i]);

Then:

<form name="formA">
<input id="pippo1" type="text" name="pippo" value="">
<input id="email1" type="text" name="email" value="">
<input name="A" type="submit"
onClick="MM_validateForm('pippo1','','R','email1', '','RisEmail');return
document.MM_returnValue" value="Invia">
</form>

<form name="formB">
<input id="pippo2" type="hidden" name="pippo">
<input id="email2" type="hidden" name="email">
</form>

....and it should work. Totally useless (catch-all) code for simple
validations, though.

Always set value="" for form elements, some browsers will do it it for
you otherwise.
Jul 23 '05 #2
RobB wrote:
val=MM_findObj(args[i]);

...to

val=document.getElementById(args[i]);
[CUT]
...and it should work. Totally useless (catch-all) code for simple
validations, though.

Rob...simply perfect :-)

Thank you very much.

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Hugo Flores | last post: by
7 posts views Thread by Darko | last post: by
6 posts views Thread by yawnmoth | last post: by
7 posts views Thread by Carlos Mendonça | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.