Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.forms[0].submit() doesn't always submit! 2

Status
Not open for further replies.

DanWalter

Programmer
Nov 29, 2000
58
US
Hi:
This one is a strange os/browser question. Only on Mac (I'm testing with OSX), and more frequently with Mozilla rather than IE, I get the weirdest behavior. After several forms have been submitted from different pages, all of a sudden the form will not submit!

Code sample:

<code>
function SetTaskAndPost(pTask)
{
if (intPosted == 0)
{
intPosted = 1;
document.forms[0].Task.value = pTask;
document.forms[0].submit();
return true;
}
}

</code>

This code is in an include file used by all pages in the site. I put a few alerts in, including just before and after the submit(). I get the alerts, but the submit action does not take place.

This is a commercial product and is currently live with this bug, so speedy replies are much appreciated!!!

Dan Walter

Dan Walter
Daniel.Walter@uvm.edu
 
Is this the name of the form: forms[0]? This appears to be a reference to an array named forms and the form causing the problem is the first element in that array. Unless you've defined this array globally, this is the likely culprit.

There's always a better way. The fun is trying to find it!
 
tviman:

forms[0] is a method of the document object. It is the alias for the first form created by the document. There is only one form per document in my code. Because the cited function is included in every page, I can't use specific form names. Again, note that this code NEVER misbehaves on Windows PCs, and will work correctly the first six or twelve times on Macs, then stop working.

Dan

Dan Walter
Daniel.Walter@uvm.edu
 

Can you post a link to your code? I've got the ability to run MacOsX here, so can look at it for you.

Regards,
Dan
 
Go to Enter the Demo area, then follow the links to Key-enter Forms. The code is called in the Cancel, Back and Next navigation buttons. You can view the source on pages where the form submits properly and on those that don't.

Dan


Dan Walter
Daniel.Walter@uvm.edu
 
DanWalter,

make sure you don't have any form element with a "name" of "submit"...this would cause a conflict


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 

There are a huge amount of Javascript errors being thrown up on some pages - more specifically something about "window.event".

AFAIK, only IE supports this - so you'll need to code around this.

I can't see why that would stop the forms submitting, but if a lot or JavaScript errors occur, it can cause screwy things to happen, so it may well be the cause.

Hope this helps,
Dan
 
Dan:
'<i>There are a huge amount of Javascript errors being thrown up on some pages - more specifically something about "window.event".'</i>


How do I reproduce or detect these errors? I have Mac OSX with IE 5.2, Safari 1.x, Mozilla 1.6 and Netscape 7.x installed. Which browser should I use to throw the errors, and how can I record them? One troubling scenario is that IE is the most reliable of browsers in this situation - it takes the longest time to "freeze" or stop submitting the page. All browsers work for some amount of time, but they all eventually cr*p out.

Thanks tremendously!

Dan

Dan Walter
Daniel.Walter@uvm.edu
 
>> "How do I reproduce or detect these errors?"

mozilla would be my choice, 1. because it does not support window.event, and 2. because it does a great job of reporting errors in the javascript console.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 

I was using Mozilla, and it has a built-in Javascript window/console.

Enable this, and you'll see all the errors scroll past.

Hope this helps,
Dan
 

BTW - There is a menu option for this, I believe, but I use the old trick of typing "javascript:" into the address bar to enable it.

If older Netscapes (v4, only I believe), you can also type "mocha:" to do this ;o)

Dan
 
Dan,

Thanks for all your help so far :)!

I have to admit to being somewhat Mozilla naive. I can open the javascript console, but I'm not sure how to use it correctly. It only shows two errors, both thrown by the Mozilla navigator. By the time one of my pages errors out (I get the "busy but available" mouse cursor), I have to Force Quit Mozilla.

How do I use the evaluate button in the console (if this is a tool that would help me diagnose this)?

Thanks again!

Dan

Dan Walter
Daniel.Walter@uvm.edu
 
If you use Firefox 0.8 for MacOSX (as I am using), you will see these errors on the first form page that presents 90-something select boxes. If you type tab + 0 + tab + 0 etc... you get the error being reported in the console.

I reckon this may be preventing other parts of your javascript from allowing all the data to be propogated properly. Just a guess.

I'm up for some debugging over Easter break... so post away!

Jeff
 
Jeff:
As a matter of fact, this error happens most reliably on a page which does contain 120 list boxes. I'll try rem'ing some of them out and see what happens.
Dan

Dan Walter
Daniel.Walter@uvm.edu
 

Dan,

One thing I noticed... On the first page, if you enter no ID, you get an alert, but if you don't specify a gender, you get a message on the page.

Why the discrepancy with validation reporting methods? Surely you'd want either an alert in both cases, or an on-page message in both cases, rather than mixing and matching? Consistency is a good thing ;o)

Dan

 
Dan: Thanks for the critique. I noticed the discrepancy during our last big release cycle, but didn't have time to get to it. It's on our bug list to fix someday.

Jeff:
BINGO!!!!!!!! [2thumbsup] The critical number is 70 select boxes. 1-70 everything works ok. 71 and up - kablooey! I've reported it as a bug to Mozilla.

THANKS ONE AND ALL!

Dan

Dan Walter
Daniel.Walter@uvm.edu
 
Not sure where to put this, so I'll add it here and maybe some replies will help me move it.

I have a script (see below) which detects the key code using "onKeyPress". It works, but when I use the "return false" code to stop the form from submitting (if the enter key is pressed) Safari ignores it. Here is the script:

<html>
<head>
<title>Javascript Test Page for Safari 1.0</title>
<script type="text/javascript">
// uses object detection technique to determine client browser
var isNav4 = document.layers; // checks for Netscape Navigator 4
var isNS6 = (document.getElementById && !document.all); // checks for Netscape 6 or higher
var isIE4 = (document.all && !document.getElementById); // checks for Internet Explorer 4
var isIE5 = (document.all && document.getElementById); // checks for Internet Explorer 5 or higher

function keyCheck(evt) {
var theKey;

// gets the key entered by the user (as each key is pushed)
if(isNav4 || isNS6) {
theKey = evt.which;
} else if(isIE4 || isIE5) {
theKey = window.event.keyCode;
}

if(theKey == 13) { // checks for enter or return key
if(isIE4 || isIE5) { window.event.returnValue = false; }
alert("You must click on the \"Get Your Score\" button in order to submit your test.");
return false;
}
}
</script>
</head>

<body onLoad="detectBrowser()">
<p>This is a test</p>
<form name="testform" action="[INSERT ANY URL HERE]" method="post">
<p><input type="text" name="keytest" onKeyPress="keyCheck(event)"></p>
</form>
</body>
</html>

Any help you can give me is greatly appreciated. This script goes on a test and we have a problem with students hitting the ENTER key before they are finished with the test and it submits. Thanks
 
justinbtci - start a new Thread and re-post your question. To post a new Thread, go to the list of messages in this forum and scroll down. There is an area towards the bottom for starting new Threads.

--Dave

P.S., when I run your code in IE6, the form does not submit, even if I comment out return false;.
 
Actually, I solved the problem. It was ignoring the "return false" code because when I called the function in my HTML code, I left out the "return" so it should have been "return keyCheck(event)" instead of just "keyCheck(event)". Anyway, thanks for your help. By the way, I took out the URL in the action value of the form. If you put in the action value to any page you want, the form will submit. Otherwise, it submits to itself. This worked for me because I was actually using a PHP file and when it submits to itself it erases any inputed values so I could tell when it sent and when it didn't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top