using hyperllinks to submit a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Ross

    using hyperllinks to submit a form

    I know that <a href="javascrip t:document.form name.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


  • Grant Wagner

    #2
    Re: using hyperllinks to submit a form

    David Dorward wrote:
    [color=blue]
    > Alexander Ross wrote:
    >[color=green]
    > > I know that <a href="javascrip t:document.form name.submit();" > works[/color]
    >
    > For some definitions of "work" - http://tom.me.uk/scripting/submit.asp
    >[color=green]
    > > 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.[/color]
    >
    > You can access it via the id attribute,
    > document.getEle mentById('id_of _form').submit( ) - but removing the
    > dependancy on JavaScript would be the better option (see the above URL).[/color]

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

    <a href="#" onclick="docume nt.forms[0].submit();retur n 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 <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    * 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-deve...upgrade_2.html


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: using hyperllinks to submit a form

      "Alexander Ross" <alexross@bleen .net> writes:
      [color=blue]
      > I know that <a href="javascrip t:document.form name.submit();" > works for
      > this,[/color]

      "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.htm l"
      onclick="docume nt.forms['formname'].submit()";retu rn 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.
      [color=blue]
      > 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.[/color]

      .... 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.f orms[0]".

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...