[Javascript] Generic submit

Alan Gardner gardner.alan at gmail.com
Fri Jan 7 17:27:31 CST 2005


Nothing special, or what I'd consider out of typical xhtml usage, but
here it is.

Ideally, I'd like to get away with something like this:
<a href="#" onClick="this.form.submit()" class="button">Submit</a>

I think the issue with this is that the <a> is not a DOM child of
<form>, so any usage of the "this" keyword wouldn't return the form
object when used in the <a> tag.

So, unless prove wrong, I'm thinking that the only way to generically
submit using an anchor tag is to somehow traverse up the node tree
until I find the <form> and get its name value.




On Fri, 07 Jan 2005 17:55:55 -0500, Shawn Milo <ShawnMilo at runbox.com> wrote:
> Please send your form declaration, and any other parts
> you think are relevant.
> 
> Shawn
> 
> Alan Gardner wrote:
> 
> >I thought it looked good, but my javascript console says "Error:
> >this.form has no properties". I've checked and the link is inside the
> >form tag. Suggestions?
> >
> >
> >On Fri, 07 Jan 2005 15:58:51 -0500 (EST), Shawn Milo
> ><ShawnMilo at runbox.com> wrote:
> >
> >
> >>Something like document.forms[0].submit(); should work, but,
> >>of course, it would only submit the first form.
> >>
> >>Also, maybe -- wait!
> >>
> >>Try this:
> >>document.forms[this.form.id].submit();
> >>
> >>If your XHTML is good, and you have ids for all of
> >>your forms, I think that this should work.
> >>
> >>Shawn.
> >>
> >>
> >>
> >>>Hi all,
> >>>If I want to use an anchor link to submit a form, but may not know the
> >>>name of the form, or how many forms are on the page, how would I best
> >>>do that?  I initially thought a simple <a href="#"
> >>>onclick="this.form.submit()"> would work, but it  appears only to work
> >>>on an input tag.  Any suggestions on how to create a generic submit
> >>>link that I can throw into any page without additional scripting?
> >>>_______________________________________________
> >>>Javascript mailing list
> >>>Javascript at LaTech.edu
> >>>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>>
> >>>
> >>>
> >>_______________________________________________
> >>Javascript mailing list
> >>Javascript at LaTech.edu
> >>https://lists.LaTech.edu/mailman/listinfo/javascript
> >>
> >>
> >>
> >_______________________________________________
> >Javascript mailing list
> >Javascript at LaTech.edu
> >https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> >
> >
> >
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>



More information about the Javascript mailing list