Connecting Tech Pros Worldwide Help | Site Map

set form action

  #1  
Old July 23rd, 2005, 08:51 PM
Andrew Poulos
Guest
 
Posts: n/a
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.getElementById("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
  #2  
Old July 23rd, 2005, 08:52 PM
Martin Honnen
Guest
 
Posts: n/a

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.getElementById("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/
  #3  
Old July 23rd, 2005, 08:52 PM
Fred Oz
Guest
 
Posts: n/a

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.getElementById("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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to set form action to same page, but getting a 'not found' error. phopman answers 6 September 4th, 2007 11:50 AM
How to overwrite the FORM ACTION attribute wwwmike@gmx.ch answers 4 January 3rd, 2007 09:25 PM
Form action attribute unchangeable? belgie answers 2 November 17th, 2005 07:26 PM
Relative folder reference in form action property? Shannon answers 1 July 20th, 2005 11:54 AM