Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Bill_W_Stephens@yahoo.com
Guest
 
Posts: n/a
#1: Mar 29 '06
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>


Randy Webb
Guest
 
Posts: n/a
#2: Mar 29 '06

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


Bill_W_Stephens@yahoo.com said the following on 3/29/2006 8:23 AM:[color=blue]
> 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.[/color]

Set the ones you don't want submitted to '' (blank) and they won't get
submitted.
[color=blue]
> Here is a simplified example that may better illustrate my question.
> Or maybe there is a better approach...
>
>
> <SCRIPT language="JavaScript">[/color]

<script type="text/javascript">
[color=blue]
> function submitform1()
> {
>
> document.myform.submit();
> }
>
> function submitform2()
> {[/color]

document.myform.Address = '';
//etc.
[color=blue]
> // logic to submit only name parameter
> document.myform.submit();
> }
>
> function submitform3()
> {
> // logic to submit only address parameter[/color]

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
[color=blue]
> 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>
>[/color]

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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Closed Thread