set form action

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Poulos

    #1

    set form action

    I have a FORM tag that looks like this:

    <form name="form1" id="form1" method="post" action="go.php" >

    I can leave off the ACTION attribute and have javascript add it on load,
    for example:

    <script type="text/javascript">
    window.onload = function() {
    var frm = document.getEle mentById("score ");
    frm.action = "go.php";
    frm.submit();
    }
    </script>
    </head>

    <body>
    <form name="frm" id="frm" method="post">

    I tried it and it seems to work but I'm uncertain if it's the "best" way
    to add an attribute.


    Andrew Poulos
  • Martin Honnen

    #2
    Re: set form action



    Andrew Poulos wrote:

    [color=blue]
    > I can leave off the ACTION attribute and have javascript add it on load,
    > for example:
    >
    > <script type="text/javascript">
    > window.onload = function() {
    > var frm = document.getEle mentById("score ");[/color]

    Neither above nor below I can see an element with id "score".
    [color=blue]
    > frm.action = "go.php";
    > frm.submit();
    > }
    > </script>
    > </head>
    >
    > <body>
    > <form name="frm" id="frm" method="post">
    >
    > I tried it and it seems to work but I'm uncertain if it's the "best" way
    > to add an attribute.[/color]

    It depends on the criteria as to what you regard as best, if you want to
    cover old browsers like Netscape 4 then it is better to use
    var frm = document.forms. frm;
    frm.action = "go.php";

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Fred Oz

      #3
      Re: set form action

      Andrew Poulos wrote:[color=blue]
      > I have a FORM tag that looks like this:
      >
      > <form name="form1" id="form1" method="post" action="go.php" >
      >
      > I can leave off the ACTION attribute and have javascript add it on load,
      > for example:
      >
      > <script type="text/javascript">
      > window.onload = function() {
      > var frm = document.getEle mentById("score ");
      > frm.action = "go.php";
      > frm.submit();
      > }
      > </script>
      > </head>
      >
      > <body>
      > <form name="frm" id="frm" method="post">
      >
      > I tried it and it seems to work but I'm uncertain if it's the "best" way
      > to add an attribute.
      >
      >
      > Andrew Poulos[/color]

      The action attribute is required, even if it's empty (though as you
      point out, most browsers will not get too upset about it).

      <URL:http://www.w3.org/TR/html401/interact/forms.html#edef-FORM>

      --
      Fred

      Comment

      Working...