By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,481 Members | 3,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,481 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>

Mar 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Bi*************@yahoo.com 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">
<script type="text/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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.