473,386 Members | 1,733 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,386 software developers and data experts.

document.submit() not work now?

I have a PHP application which I wrote last year - and the JavaScript
worked fine then. For some reason, now it doesn't - neither on IE nor
Firefox. Has something changed?

When I click on my HTML link now (which executes a JS function), the
firefox JS console tells me:
Error: document.SubjectsForm.submit is not a function

Any help would be much appreciated. Thanks!

The script, fairly explanatory, is as follows (it's been trimmed of
irrelevant code):
<html>
<head>
<title>Title here</title>
</head>

<body bgcolor="#FFFFFF" background="/images/bg.gif">

<SCRIPT language="JavaScript" type="text/javascript">
<!-- Hide script from old browsers
function submitForm() {
document.SubjectsForm.status.value='add_entry';
document.SubjectsForm.submit();
}
// unhide script -->
</SCRIPT>
<form name="SubjectsForm" action="mod_enrolment.php" method="POST">
<input type="hidden" name="status" value="ch_exams">

<a href="javascript: submitForm();" class="noline"> Add Subject</a>
<input type="hidden" name="user" value="tparker">
<input type="submit" name="submit" value="Update Subjects">

</form></p>

</body>
</html>

Jul 23 '05 #1
5 33853
te************@gmail.com wrote:
I have a PHP application which I wrote last year - and the JavaScript
worked fine then. For some reason, now it doesn't - neither on IE nor
Firefox. Has something changed?

When I click on my HTML link now (which executes a JS function), the
firefox JS console tells me:
Error: document.SubjectsForm.submit is not a function
You have named your submit button "submit", so your reference above is
to the button, not the submit method of the form. Remove the button's
name or change it.

Any help would be much appreciated. Thanks!

The script, fairly explanatory, is as follows (it's been trimmed of
irrelevant code):
<html>
<head>
<title>Title here</title>
</head>

<body bgcolor="#FFFFFF" background="/images/bg.gif">
bgcolor and background are both depreciated, use the equivalent style
properties, preferably in a css style element.

<SCRIPT language="JavaScript" type="text/javascript">
The language attribute is depreciated, remove it. Keep the type
attribute, it is required.
<!-- Hide script from old browsers
This is pointless and potentially harmful - do not attempt to hide
scripts.
function submitForm() {
document.SubjectsForm.status.value='add_entry';
document.SubjectsForm.submit();
}
// unhide script -->
</SCRIPT>
<form name="SubjectsForm" action="mod_enrolment.php" method="POST">
<input type="hidden" name="status" value="ch_exams">

<a href="javascript: submitForm();" class="noline"> Add Subject</a>
Subverting an A element this way is bad. There is no need for the
javascript pseudo-protocol, the href should contain a URI that links to
an appropriate resource for non-javascript browsers. The script should
be assigned to an onclick event:

<a href="whyThisDidntWork.html" onclick="submitForm();" ...>...</a>

The purpose of the link seems completely unnecessary. Why not call
submitForm() from the form's onsubmit event? Then you have no issues
with links that don't work or the usability issue associated with a
link that attempts to submit a form. And the script will be called
regardless of how the form is submitted (provided javascript support is
available to the user).

Which probably also infers a change of name to 'changeStatus' or
similar and removal of the call to the form's submit method.

You should always assume that your script may not have run before the
form is submitted.
<input type="hidden" name="user" value="tparker">
<input type="submit" name="submit" value="Update Subjects">
Change the name or remove it (it seems superfluous anyway).

</form></p>
Closing 'P' tag that has no opening tag. Its placement infers that the
opening tag was before the form, but a P element can't contain a
block-level element (such as a form).

</body>
</html>

--
Rob
Jul 23 '05 #2
RobG wrote:
You have named your submit button "submit", so your reference above is
to the button, not the submit method of the form. Remove the button's
name or change it.
Thanks for the help Rob - you've managed to solve my problem. This was
the main problem, as you identified, which leaves me scratching my head
as to why it worked before or (more likely), when I made a change to
the code without even realising I had changed something.

I'm definitely not a JavaScript person - nor fancy HTML either. I'm
more of a PHP guy. I detest dreamweaver or most WYSIWYG programs since
their code is absolutely AWFUL. And doing everything by hand, it's a
pain in the arse to delve into complicated stuff like layers and such -
which half the time aren't necessary anyways. What happened to the days
when things were nice and simple?

bgcolor and background are both depreciated, use the equivalent style
properties, preferably in a css style element.
- as with the above, <body> would do fine for me until the day it is no
longer supported. I can't say i'm a fan of CSS and most of what I want
to develop doesn't need it.

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


The language attribute is depreciated, remove it. Keep the type
attribute, it is required.


I'll take your advice here. But is there any particular reason for
this? I notice most of the free JavaScripts include the opening tags
like this.

<!-- Hide script from old browsers


- They also (a lot of them) include a bit which ignores the script. Was
there any traditional reason for this before?

Subverting an A element this way is bad. -snip-
<a href="whyThisDidntWork.html" onclick="submitForm();" ...>...</a>
Oops. Actually what I used was:

<a href=\"javascript: void(0);\" onclick=\"submitForm();return
false;\">

But out of desperation when things didn't work I started playing around
with some changes, and must have used the wrong source code in my
posting.

Is javascript: void(0) acceptable? Or you would still suggest a real
link? Making the link without going running the function is as good as
not running it at all... so i'm not sure it would make a difference for
compatibility reasons.

The purpose of the link seems completely unnecessary. Why not call
submitForm() from the form's onsubmit event?


I need to run SubmitForm() becuase I want to add a hidden form variable
to the form before I submit it. The standard form submit button I have
(which would submit without this variable) achieves something else when
the resulting PHP page is loaded. Is there a better way to do this
though?

What I really need then is for two different ways to submit the form,
but one with an extra variable attached. Also I would prefer to use a
link since it looks nicer in my page.
Thanks again for your help.

Terence

Jul 23 '05 #3
te************@gmail.com wrote:
RobG wrote:
[...]
bgcolor and background are both depreciated, use the equivalent style
properties, preferably in a css style element.

- as with the above, <body> would do fine for me until the day it is no
longer supported. I can't say i'm a fan of CSS and most of what I want
to develop doesn't need it.


CSS is much cleaner and simpler, learn to use it and you'll be
surprised how you got along without it.

<SCRIPT language="JavaScript" type="text/javascript">
The language attribute is depreciated, remove it. Keep the type
attribute, it is required.

I'll take your advice here. But is there any particular reason for
this?


There is absolutely no need for it as far as I know, but one of the
gurus may be lurking and fill in on the history.
I notice most of the free JavaScripts include the opening tags
like this.
Most probably because either the authors couldn't be bothered to fix
their code or they don't know any better.

<!-- Hide script from old browsers

- They also (a lot of them) include a bit which ignores the script. Was
there any traditional reason for this before?


Way back level 2 browsers didn't know how to deal with script elements,
which were introduced with HTML 3.2. It is extremely unlikely anyone
is still surfing the web with Netscape 2 (or earlier) and if they are,
displaying the code from script elements is likely the least of their
worries.


Subverting an A element this way is bad. -snip-
<a href="whyThisDidntWork.html" onclick="submitForm();" ...>...</a>

Oops. Actually what I used was:

<a href=\"javascript: void(0);\" onclick=\"submitForm();return
false;\">

But out of desperation when things didn't work I started playing around
with some changes, and must have used the wrong source code in my
posting.


The backslashes before the quotes are unnecessary.

Is javascript: void(0) acceptable? Or you would still suggest a real
link? Making the link without going running the function is as good as
not running it at all... so i'm not sure it would make a difference for
compatibility reasons.
That is the reason why A elements shouldn't be turned into buttons.
Users without JavaScript will expect something to happen, but nothing
does. You are left in a quandary as to whether to navigate to a "you
don't have JavaScript page" or just let your visitor think your site is
broken.
The purpose of the link seems completely unnecessary. Why not call
submitForm() from the form's onsubmit event?

I need to run SubmitForm() becuase I want to add a hidden form variable
to the form before I submit it. The standard form submit button I have
(which would submit without this variable) achieves something else when
the resulting PHP page is loaded. Is there a better way to do this
though?


Why not hide the A by default, and only reveal it if JavaScript is
supported? Then non-JS users won't try to click it.

<a id="XX" href="#" onclick="submitForm();return false;"
style="display: none;">

<script type="text/javascript">
if ( document.getElementById ) {
document.getElementById('XX').style.display = '';
} else if ( document.all ) {
document.all['XX'].style.display = '';
}
</script>

Or if you have many links to expose, you may want to use an onload
function to reveal all of them. If you want to maintain the link's
position in the page even when it isn't shown, use visibility:
hidden/visible instead of display.

What I really need then is for two different ways to submit the form,
but one with an extra variable attached. Also I would prefer to use a
link since it looks nicer in my page.


Using the above strategy, users without JS will only ever see the
submit button and so will only use that.

Non-JS users will never have the extra field added.

Hope that helps!
--
Rob
Jul 23 '05 #4
te************@gmail.com wrote:
RobG wrote: [...]
<!-- Hide script from old browsers

- They also (a lot of them) include a bit which ignores the script. Was
there any traditional reason for this before?


I knew this was here but took a while to find it:

<URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/1d19a74dfc73fec6/c2e324e15908a9b0?q=hide+script&rnum=18&hl=en#c2e32 4e15908a9b0>

--
RobG
Jul 23 '05 #5
Thanks again for the help - will try out the suggestions.

So far i've got the submit link to work the way I want it to now - but
i'll be gradually improving the site, and it's probably about time I
learned JavaScript too - since PHP can only get me so far. But
anyways... thanks again for the help! Much appreciated.

Terence

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the...
2
by: Miles Davenport | last post by:
My Javascript is rather rusty :( ... and I need to do change some form values, in the folowing way: (1). I have the following a href (wrapped in PHP), which calls processForm. ==== <input...
6
by: skubik | last post by:
Hi everyone. I'm attempting to write a Javascript that will create a form within a brand-new document in a specific frame of a frameset. The problem is that I can create the form and input...
4
by: jiing.deng | last post by:
I want to transfer a value "re1" to ldapDeleteUserExec.php The "alert(document.ha)" appears a dialog and shows "undefined." The "alert(document)" shows "object" But there seems some problem:...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
3
by: MeNotHome | last post by:
I am trying to automate web browser navigation and form fill out in vb.net Why doesn't this work? AxWebBrowser1.Document.Forms(0).All("action-download").click() I also tried...
5
by: antonyliu2002 | last post by:
Hi, It looks like so many people are having problems with the javascript submit in firefox. I searched around, but haven't found a solution yet. Mostly, people were saying, try this or try...
2
by: janulam | last post by:
Hello, I have following code snippet: ... function submitForm() { document.forms.submit(); } ..
2
by: ChrisLA | last post by:
Hi; I've seen lots of discussion & disagreement on this issue, so any good explanation would be appreciated. Some people seem to think that "document.GetElementByID("MyName").submit(); should...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.