473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 2111
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: nec | last post by:
Hi, I'm having trouble calling a function thats located in a iFrame from the parent. Shortly, i can't figure out the location in DOM. In IE it works fine with a simple line of...
6
by: Cliff R. | last post by:
Hi, I use a handy little Javascript Flash detection script on a number of sites (copied below). Usually works great, but I just started trying Firefox and it's not working. A few browsers are...
6
by: rwsims | last post by:
This works in firefox, not at all in ie6. I'm not getting any errors, but only the doalert() function works, not the click() function. I'm sure there's something obvious, but I'm just not seeing...
1
by: Hugo Flores | last post by:
Hello I have this code in actionscript that calls javascript: actionscript: zoom_in = function () { var tw1:Tween = new Tween(mc_1, "_width", Regular.easeOut, mc_1._width, 0, 1, false);...
4
by: badaczewski | last post by:
The following javascript appears on a popup window. <script language="javascript" type="text/javascript"> function InsertContact(value) { window.opener.CallBackContact(value); window.close();...
7
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new...
6
by: yawnmoth | last post by:
I'm trying to write a so-called bookmarklet for a specific web app and am having some difficulty. One of the names of a specific forms inputs is submit. As such, doing...
7
by: Carlos Mendonça | last post by:
Has anyone managed to get ClickOnce to work with Firefox? It seems to me that it still has the same issues VS 2K5 had. I appreciate any comments or tips.
7
by: Andrew Poulos | last post by:
Say I have this foo = function() { // blah }; bar = fuction(fnName) { /* If fnName equalled "foo" * How do I test that foo, as a function, * exists and then, if it exists, call it?
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.