multiple submit buttons: Can I control which values will be submited?

B

Bill_W_Stephens

I have a complicated page with several submit buttons. I don't want to
create multiple forms because much of the input is shared and the code
is getting very ugly. However I would like to determine which values
will be submited.

Here is a simplified example that may better illustrate my question.
Or maybe there is a better approach...


<SCRIPT language="JavaScript">
function submitform1()
{

document.myform.submit();
}

function submitform2()
{
// logic to submit only name parameter
document.myform.submit();
}

function submitform3()
{
// logic to submit only address parameter
document.myform.submit();
}
</SCRIPT>


<form name="myform" action="#">
<TABLE>
<TR><TD>Name</TD><TD><input type='text' name='Name'></TD></TR>
<TR><TD>Address</TD><TD><input type='text' name='Address'></TD></TR>
<TR><TD>Phone</TD><TD><input type='text' name='Phone'></TD></TR>
<TR><TD></TD><td><input type="button" onClick="submitform1()"
value="submit all variables"> </TD></TR>
<TR><TD></TD><td><input type="button" onClick="submitform2()"
value="submit just name"> </TD></TR>
<TR><TD></TD><td><input type="button" onClick="submitform3()"
value="submit just address"> </TD></TR>
</TABLE>
</form>
 
R

Randy Webb

(e-mail address removed) said the following on 3/29/2006 8:23 AM:
I have a complicated page with several submit buttons. I don't want to
create multiple forms because much of the input is shared and the code
is getting very ugly. However I would like to determine which values
will be submited.

Set the ones you don't want submitted to '' (blank) and they won't get
submitted.
Here is a simplified example that may better illustrate my question.
Or maybe there is a better approach...


<SCRIPT language="JavaScript">

function submitform1()
{

document.myform.submit();
}

function submitform2()
{

document.myform.Address = '';
//etc.
// logic to submit only name parameter
document.myform.submit();
}

function submitform3()
{
// logic to submit only address parameter

document.myform.Name='';

Name might not be a good name for an input field though. Forms have a
name property and could cause conflicts if you accidentally name an
input name instead of Name
document.myform.submit();
}
</SCRIPT>


<form name="myform" action="#">
<TABLE>
<TR><TD>Name</TD><TD><input type='text' name='Name'></TD></TR>
<TR><TD>Address</TD><TD><input type='text' name='Address'></TD></TR>
<TR><TD>Phone</TD><TD><input type='text' name='Phone'></TD></TR>
<TR><TD></TD><td><input type="button" onClick="submitform1()"
value="submit all variables"> </TD></TR>
<TR><TD></TD><td><input type="button" onClick="submitform2()"
value="submit just name"> </TD></TR>
<TR><TD></TD><td><input type="button" onClick="submitform3()"
value="submit just address"> </TD></TR>
</TABLE>
</form>

Have Radio buttons instead of input buttons, then a normal submit
button. The radio buttons would tell the server what fields to
process/ignore and then it doesn't rely on client-side scripting.
 

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,772
Messages
2,569,593
Members
45,113
Latest member
Vinay KumarNevatia
Top