HighDots Forums  

Re: document.submit() not work now?

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: document.submit() not work now? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
terence.parker@gmail.com
 
Posts: n/a

Default Re: document.submit() not work now? - 06-03-2005 , 11:10 PM






RobG wrote:
Quote:
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?


Quote:
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.

Quote:
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.


Quote:
<!-- 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?


Quote:
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.


Quote:
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



Reply With Quote
  #2  
Old   
RobG
 
Posts: n/a

Default Re: document.submit() not work now? - 06-04-2005 , 06:40 AM






terence.parker (AT) gmail (DOT) com wrote:
Quote:
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.

Quote:

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.

Quote:
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.


Quote:
<!-- 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.

Quote:


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.

Quote:
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.

Quote:
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.

Quote:
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


Reply With Quote
  #3  
Old   
RobG
 
Posts: n/a

Default Re: document.submit() not work now? - 06-04-2005 , 06:55 AM



terence.parker (AT) gmail (DOT) com wrote:
Quote:
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


Reply With Quote
  #4  
Old   
terence.parker@gmail.com
 
Posts: n/a

Default Re: document.submit() not work now? - 06-19-2005 , 01:31 PM



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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.