473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
1 2694
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phillip Windell | last post by:
This is really an HTML question I think, but it probably won't take much effort to answer (unless I'm answering or course). The HTML is all ASP generated and the ASP generates exactly what I want...
2
by: sandyde2 | last post by:
Hi all, I get the tough problem and expect to get help.. In a html page, I dynamically created many forms which named as NO+business_id. In each form there are two submit buttons to...
6
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form...
3
by: M | last post by:
i am using submit buttons to send the user to different parts of a wizard. i am using if (if attribute.step1 exists) statements to send them to the appropriate section based on which submit button...
3
by: Mark | last post by:
This is a solution... Often users want to keep clicking "submit" when they are waiting for server processing. Most apps these days like to disable the submit button to prevent this. You can't just...
5
by: Alex Maghen | last post by:
In ASPX 2.0 with MasterPages and all that, my entire page only has one actual <FORM>. But there are several different sections of the page that provide what are functionally separate forms with...
5
by: mayur_hirpara | last post by:
Hi, I have been developing web applications for a while now. However, as I was thinking through the architecture I really don't understand the "How server can identify between which buttons has...
5
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
4
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all I have the following code: I am trying to use the value of the image button to evaluate what plan the user has chosen, i.e. it request("submit1")="Basic", then the user chose basic plan...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.