Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple buttons for form submit

Status
Not open for further replies.

rico14d

Programmer
Joined
Apr 8, 2002
Messages
135
Location
GB
Hi,

Ive used some javascript to specify a different form action
i.e.

form.action = "new_page.asp"

depending on which button was pressed.

It works fine but I also wanted a hidden text box that is also called action. The javascript above gives an error as it thinks im trying to reference the text box.

Is there an easy way to get round this without renaming my hidden text box?

Thanks,
Rich.
 
This is just an idea, but try using both an
Code:
id=
tag and a
Code:
name=
tag in your
Code:
<input>
element for your hidden text box. The name can continue to be &quot;action&quot;, but make the id something else, like &quot;action_text&quot;. The JavaScript should only try to reference the id, but when you process the form with your CGI program, it should use the name.

Let me know if this works.

--
-- GhodMode
 

Or you can try using:

Code:
form.setAttribute('action', 'new_page.asp');

No idea if it will work or not, but give it a bash ;o)

Dan
 
Thanks for you replies, but...

GhodMode -
The javascript still tried to reference the id and the name of the object even when they had different values.

Dan -
That set the form.action ok. But still tried the form element called action if it was present.

Ive had a good look round and found this response in a different forum.
---------------------------------------------------
Here's the object hierarchy you're dealing with:

window.document.forms[0].action

That last is the form's .action property, usually written to with <form action=&quot;....&quot;>. But it's just a variable - named 'action' - and, since all form element names become form properties (of that name) as well, if you name an element 'action' you'll over-write the default .action property in the process.
---------------------------------------------------

So basically, i think it might not be possible.

Thanks anyway,
Rich
 

Nope - I think you could be right.

Rename your &quot;action&quot; field... After all, it can't be *that* hard to modify your server-side code, right?

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top