PDA

View Full Version : Weird error



Synergyauto
01-21-2010, 05:14 PM
Hi folks,

I'm updating code that's been in use for years now. Consider the following:



<script language="javascript">
function submitForm()
{
frm.submit();
}
</script>

....//body tag, etc

<form name="frm" action="blahblah">
//button here that calls submitForm() on click;
</form>



This is, of course, a highly stripped down version but you get the idea.

The problem, this site was not a standalone site before, i.e. www.mysite.com, but was in a subdirectory of our intranet. We've since upgraded it to ColdFusion 8 and made it a standalone site.

frm.submit() no longer works and required us to change it to document.frm.submit().

Any ideas why? :confused:

abduraooft
01-21-2010, 05:27 PM
frm.submit() no longer works and required us to change it to document.frm.submit().
It has nothing to do with server or server configuration. It's javascript code, which is purely client side. frm.submit(); may work in stupid IE, but document.frm is the correct/standard way to refer a form element.

Synergyauto
01-21-2010, 06:06 PM
I agree that it's client side only of course, but the question is, why doesn't frm.submit() work anymore? The only thing changed was the server side configuration. The browser used has remained the same - IE 6.0

Old Pedant
01-22-2010, 12:42 AM
I'll bet that CF8 has (finally) moved to using XHTML. And then even MSIE 6 doesn't support that very old style code.

Open the page, click on VIEW menu, click on SOURCE menu.

Do you see "XHTML" in the first one or two lines of the code there? If so, voila.

Synergyauto
01-22-2010, 05:21 PM
No, afraid not. What I see is:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
..etc.


Although that's a very good answer, I may need to probe that further.

abduraooft
01-22-2010, 05:23 PM
No, afraid not. What I see is:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
..etc.


Although that's a very good answer, I may need to probe that further.
Anyway, that's an incomplete DOCTYPE! Read http://www.alistapart.com/articles/doctype

Synergyauto
01-22-2010, 05:50 PM
You are correct, and as I'm a contractor here and my last day is next Friday, I'm not about to go changing every page in their 40+ applications. lol

Amazingly, this company of 32,000+ employees does not have a standard footer or header file in any of their apps! :eek:

As the Doctype has not changed recently I must assume that's not the cause of the issue I posted about though.

Old Pedant
01-23-2010, 02:42 AM
You're gonna love this one.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script>
function FOO( ) { frm.submit(); }
</script>

</head>
<body>
<form name="frm">
<input name="foo" value="zamboni">
<input type=button value="push" onclick="FOO();">
</form>
</body>
</html>

Works like a charm using MSIE 7.

You sure you don't have more than one something-or-other named "frm" on those pages????

Synergyauto
01-23-2010, 04:26 AM
1) This is on IE 6
2) If I had another object named "frm" then why would adding document onto the front of it help?

_Aerospace_Eng_
01-23-2010, 10:25 AM
1) This is on IE 6
2) If I had another object named "frm" then why would adding document onto the front of it help?

It wouldn't help but then the browser will look for an element with name="frm" and find more than one (if there was one) and it wouldn't submit the form because it wouldn't know what to do with the other element however document.frm.submit() is a standard. Another problem that could prevent the form from submitting is there is an element with name="submit". That will cause the submit() method to stop working. Also why the use of a button to call a js function that submits the form? I guess things to process first but then again why can't you just use onsubmit and return the result of the function e.g. onsubmit="return submitForm()".

Synergyauto
01-23-2010, 07:17 PM
I guess my point is, if there were two items named "frm" then adding document. to the js calls would still fail as it wouldn't know which one you were referring to.

There's alot more to the submitForm() function than I listed, it was just a brief example. It was too much to put inline with the submit buttons inline click call.

bdl
01-23-2010, 07:33 PM
Another problem that could prevent the form from submitting is there is an element with name="submit".

This is the comment I wanted to make; I had this exact problem once updating an old site. Stupidly named the "submit button" to "submit". I always make a point to have a consistent naming convention now, e.g. "submitBtn" or "usernameInput". May be a few more characters to type, but it makes life easier in the long run.

bdl
01-23-2010, 07:34 PM
You are correct, and as I'm a contractor here and my last day is next Friday, I'm not about to go changing every page in their 40+ applications. lol

Amazingly, this company of 32,000+ employees does not have a standard footer or header file in any of their apps! :eek:

Yikes.

Synergyauto
01-23-2010, 07:36 PM
A good point and worthy of remembering for later. Although, again, if there was something named submit it would still be named submit, and adding "document." to the front of frm.submit() wouldn't change that.

I'm looking for reasons that adding "document." to the front of a frm.submit() call would make it start working all of a sudden when nothing else but the server language (coldFusion) had changed.

Old Pedant
01-23-2010, 11:12 PM
I guess I wasn't clear.

Try this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script>
function FOO( ) { frm.submit(); }

var frm = "yowser";
</script>

</head>
<body>
<form name="frm">
<input name="foo" value="zamboni">
<input type=button value="push" onclick="FOO();">
</form>
</body>
</html>

Now it no longer works in *ANY* browser.

Now change from

function FOO( ) { frm.submit(); }

to

function FOO( ) { document.frm.submit(); }

and it works. Yes, even with the presence of the "frm" variable.

The "var" named "frm" is *NOT* a part of the document, so *that* is why adding "document." to the front of "frm.submit()" could change behaviors.

That's why I asked

You sure you don't have more than one something-or-other named "frm" on those pages????


And the reason I mentioned it worked in MSIE 7 was sort of in refutation of my earlier comments on XHTML and IE6. That is, IE7 behaves the same as IE6 when you are still using HTML.

Synergyauto
01-23-2010, 11:16 PM
I guess I wasn't clear.

Now it no longer works in *ANY* browser.



That's just it though, it USED to work without "document." in front of it, now after changing the server version (and nothing else), it no longer does and I had to add "document." in front of it to get it to work. And that's the question, why did it work before, but now required "document." in front of it?

Did someone download a new version of java to all our browsers? Did upgrading from Coldfusion 6 to 8 introduce some new way of interpreting JS code? These are the questions :)

Old Pedant
01-23-2010, 11:33 PM
I was only asking if perhaps CF8 has added some JS *variable* named "frm" to your pages.

Showing that *if* it did that then it explains everything.

But if you bring the page up in the browser and do a VIEW-->>SOURCE and don't see anything else named "frm" then no, I don't get it at all.

I don't suppose you could post (or PM?) the actual HTML of the generated page??

Synergyauto
01-23-2010, 11:44 PM
I'm afraid the page in question is part of a highly secure intranet, and cannot post code from it.

Although JS is purely client side, as only the server version has changed to bring this issue about and nothing else, logical deduction points to it. Exactly how it changes things I may never know, but it's an answer for the higher ups who were wondering, for now.

I appreciate everyone's input on this matter. :)

Take care!

Old Pedant
01-23-2010, 11:51 PM
Certainly agree with your conclusion that it's CF-based.

But if it's not a new variable named "frm" then I'm mystified.

Obviously something we are missing, but can't guess what.

Puffin the Erb
01-24-2010, 03:03 PM
Are you sure it is not a browser security issue? For example, browsers will often have a setting that rejects submission of non-encrypted form data ( with or without a prompt ). If your network is highly secure ( as stated ) then this preference may have been implemented.

Just to clarify, the script will work with IE because it supports document.all. Firefox will support document.all only if the page is rendered in quirks mode.

Old Pedant
01-24-2010, 08:28 PM
But, Puffin, he says the client *only* uses MSIE 6.

I don't think we can answer this one without seeing the page, and we can't see the page.