submit form data approaches

M

Matt

I tried to figure out how many approaches to submit form data. Here's my
attempts.
Please advise. Thanks!!

1) html submit button, most commonly used.

<form name="formName" action="url" method="post">
<input type="submit">

2) html regular button, and a JavaScript to invoke the form.submit() method

<form action="url"
function submitForm()
{ //etc...
formName.submit();
}
<input type="button" onClick="submitForm()">

3) onsubmit event handling
<form name="formName" action="url" method="post" onsubmit="return
submitForm()">
function submitForm()
{ //etc...
//formName.submit(); //NOT NECESSARY!!
}
<input type="submit">
 
J

Jeff Thies

Matt said:
I tried to figure out how many approaches to submit form data.

Or, none of the below.

Typically this is done with three submit buttons, each with the same name
but a different value.

Have your server script parse which button was used by looking at the
value, and then send the data on it's way.

If you must use javascript, then do something like this

<form onsubmit="changeAction()">....

function changeAction(){
var form=document.forms[0];

if(form['submit_name'].value == 'action1'){
form.action='some_server_script...

You may have to adjust that as I'm not sure if javascript will read the
pushed submit value without some help.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top