Connecting Tech Pros Worldwide Help | Site Map

set form action

Andrew Poulos
Guest
 
Posts: n/a
#1: Jul 23 '05
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
Martin Honnen
Guest
 
Posts: n/a
#2: Jul 23 '05

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/
Fred Oz
Guest
 
Posts: n/a
#3: Jul 23 '05

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