using hyperllinks to submit a form

A

Alexander Ross

I know that <a href="javascript:document.formname.submit();"> works for
this, but can you use a hyperlink to submit a form WITHOUT assigning the
form tags name attribute a value. The site I am currently working on is
supposed to be HTML 4 (w3c) complient, but according to the HTML validator
the name attribute has been depreciated and should no longer be used. I'm
not saying I agree with this, just that I have little choice in the matter.
Thoughts?

Alex
 
G

Grant Wagner

David said:
For some definitions of "work" - http://tom.me.uk/scripting/submit.asp


You can access it via the id attribute,
document.getElementById('id_of_form').submit() - but removing the
dependancy on JavaScript would be the better option (see the above URL).

The default document object in most browsers contain a list of form objects on
the page as a 0-indexed array. Using document.getElementById() is unnecessary.

<a href="#" onclick="document.forms[0].submit();return false;">Submit</a> will
work just fine.

Although I agree, remove the dependancy on the link entirely and use a normal
<input type="submit" ...> with CSS to make it look like a link. Sure, in older
browsers it'll be a big ugly button, but in newer browsers it'll look like a
link, and in all browsers it should submit the form, regardless of JavaScript
support.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
L

Lasse Reichstein Nielsen

Alexander Ross said:
I know that <a href="javascript:document.formname.submit();"> works for
this,

"this" == subject. (Putting vital parts of a message in the subject is
highly distracting).

Using the javascript: pseudo protocol is a bad idea. You should at least
use

<a href="nonJS.html"
onclick="document.forms['formname'].submit()";return false;">

where "nonJS.html" expains why you can't build a functional page
without javascrtip.

A better solution is to use asubmit button inside the form.
but can you use a hyperlink to submit a form WITHOUT assigning the
form tags name attribute a value. The site I am currently working on is
supposed to be HTML 4 (w3c) complient, but according to the HTML validator
the name attribute has been depreciated and should no longer be used.

.... however, one should use the "id" attribute instead.

If that fails, you can index "document.forms" with integers too,
so the first form is "document.forms[0]".

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top