Connecting Tech Pros Worldwide Help | Site Map

set form action

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 07:51 PM
Andrew Poulos
Guest
 
Posts: n/a
Default 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.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, 07:52 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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, 07:52 PM
Fred Oz
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.