473,749 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which Submit button was pressed?

Hello,

I have 1 HTML form with 4 submit buttons and 10 textfield entry areas.

If submit button1 is pressed I need to make sure that all 10 textfield
entries have been filled before submitting the form.

If submit button2 is pressed I need to make sure that only textfied1
is filled before submitting the form.

How do I go about doing the above check?

I used -onSubmit with the HTML form tab, but I am not sure how to
check which button was pressed, i.e., how do I reference submit1,
submit2 button in my logic of:
if submit1 then
if all textfields have been completed then
return true
else
return false

I also tried to used -onClick with each Submit button, but returning
false if all textfields have not been filled still causes the form to
get submitted to the CGI script because the HTML form submit itself
has no -onSubmit handler.

THank you!
Jul 20 '05 #1
8 14646
> I used -onSubmit with the HTML form tab, but I am not sure how to
check which button was pressed, i.e., how do I reference submit1,
submit2 button in my logic of:
if submit1 then
if all textfields have been completed then
return true
else
return false

I also tried to used -onClick with each Submit button, but returning
false if all textfields have not been filled still causes the form to
get submitted to the CGI script because the HTML form submit itself
has no -onSubmit handler.


You could do something along the lines of:

var canSubmit;

...

<form onsubmit="retur n canSubmit;">

<submit onclick="canSub mit = validator1( );" />
Jul 20 '05 #2
try to write a function that will check to see
if the forms are blank or not when the button is pressed.

Can be done with one function or 2 functions. One woulds check all
alternatively create 2 and assign one to each button.

al**@paul.rutge rs.edu (Syed Ali) wrote in message news:<30******* *************** ***@posting.goo gle.com>...
Hello,

I have 1 HTML form with 4 submit buttons and 10 textfield entry areas.

If submit button1 is pressed I need to make sure that all 10 textfield
entries have been filled before submitting the form.

If submit button2 is pressed I need to make sure that only textfied1
is filled before submitting the form.

How do I go about doing the above check?

I used -onSubmit with the HTML form tab, but I am not sure how to
check which button was pressed, i.e., how do I reference submit1,
submit2 button in my logic of:
if submit1 then
if all textfields have been completed then
return true
else
return false

I also tried to used -onClick with each Submit button, but returning
false if all textfields have not been filled still causes the form to
get submitted to the CGI script because the HTML form submit itself
has no -onSubmit handler.

THank you!

Jul 20 '05 #3
al**@paul.rutge rs.edu (Syed Ali) wrote in message news:<30******* *************** ***@posting.goo gle.com>...
Hello,

I have 1 HTML form with 4 submit buttons and 10 textfield entry areas.

If submit button1 is pressed I need to make sure that all 10 textfield
entries have been filled before submitting the form.

If submit button2 is pressed I need to make sure that only textfied1
is filled before submitting the form.

How do I go about doing the above check?

I used -onSubmit with the HTML form tab, but I am not sure how to
check which button was pressed, i.e., how do I reference submit1,
submit2 button in my logic of:
if submit1 then
if all textfields have been completed then
return true
else
return false

I also tried to used -onClick with each Submit button, but returning
false if all textfields have not been filled still causes the form to
get submitted to the CGI script because the HTML form submit itself
has no -onSubmit handler.


Try using both methods. Have the submit button's onclick() methods
set a global status variable to the result of their check of the
text fields. Have the form's onsubmit() method check that variable.

If you want to have an error message that varies depending
on which button was clicked, have the onclick() methods store
an error message if there's a problem. Otherwise they store
null. The form's onsubmit() would display the error
message, if any, and return false, otherwise return true.
Jul 20 '05 #4
Lee
Syed Ali said:

Hello,

I have 1 HTML form with 4 submit buttons and 10 textfield entry areas.

If submit button1 is pressed I need to make sure that all 10 textfield
entries have been filled before submitting the form.

If submit button2 is pressed I need to make sure that only textfied1
is filled before submitting the form.

How do I go about doing the above check?


You can't check that for sure, because you don't know that the visitor
has JavaScript enabled. If they have JavaScript enabled, you can check
it for their convenience, but you also have to be able to validate on
the server side, so you also need to provide a way for the server to
know which button was pressed.

This works on the client side, and also sends enough information to the
server to allow it to perform the same sort of validation.

Note that I'm taking your specification literally to mean that if the
second button is pressed, that *only* the first field should be filled:
<html>
<head>
<script type="text/javascript">
function validate(f,whic hCase){
var textfieldCount= 0;
var hasValueCount=0 ;
var firstHasValue=0 ;
for(var i=0;i<f.element s.length;i++){
if(f.elements[i].type=="text"){
textfieldCount+ +;
if(-1!=f.elements[i].value.search(/\S/)){
hasValueCount++ ;
if(textfieldCou nt==1){
firstHasValue++ ;
}
}
}
}
if(whichCase==" button1"){ // all must have values
if(hasValueCoun t==textfieldCou nt){
return true;
}else{
alert ("all fields must have values.");
return false;
}
}else{ // only first may have value
if((hasValueCou nt==1)&&(firstH asValue)){
return true;
}else{
alert("the first field (only) must have a value");
return false
}
}
}
</script>
</head>
<body>
<form onsubmit="retur n validate(this,w hichPressed)">
<input><input>< input><input>
<input name="whichSubm it" type="submit" value="button1"
onclick="whichP ressed=this.val ue">
<input name="whichSubm it" type="submit" value="button2"
onclick="whichP ressed=this.val ue">
</form>
</body>
</html>

Jul 20 '05 #5
Lee wrote on 16 dec 2003 in comp.lang.javas cript:
<input name="whichSubm it" type="submit" value="button1"
onclick="whichP ressed=this.val ue">
<input name="whichSubm it" type="submit" value="button2"
onclick="whichP ressed=this.val ue">


If you want the texts on the buttons to be the same, do:
<input name="button1" type="submit" value="Submit me"
onclick="whichP ressed=this.nam e">
<input name="button2" type="submit" value="Submit me"
onclick="whichP ressed=this.nam e">
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #6
@SM
Syed Ali a ecrit :

Hello,

I have 1 HTML form with 4 submit buttons and 10 textfield entry areas.

If submit button1 is pressed I need to make sure that all 10 textfield
entries have been filled before submitting the form.

If submit button2 is pressed I need to make sure that only textfied1
is filled before submitting the form.

How do I go about doing the above check?


<script type="text/javascript"><!--
function verifOne(nameOf Field){
if(nameOfField. value=='') {
alert(nameOfFie ld.name+' not filled');
nameOfField.foc us();
return false;
}
else return true;
}
function verifAll(MyForm ){
ok=0;
for(var i=0;i<MyForm.le ngth;i++) {
if(MyForm.eleme nts[i].type=="text")
if(!(verif1(MyF orm.elements[i])))
{ ok=1; return; }
}
if(ok==0) return true;
else return false;
}
// --></script>

<form action="blabla" etc>
<input type=button value="Submit one field"
onclick="if(ver ifOne(this.form .Firstname)) this.form.submi t();">
<input type=button value="Submit All"
onclick="if(ver ifAll(this.form )) this.form.submi t();">
</form>

Not tried !

-- -----
@SM
move away *OTEZ-MOI* from my reply url
Jul 20 '05 #7
Thank you to everyone who responded.

What worked me for me is setting a global var with -onlick on each
submit button and then checking the value of that global var in
-onSubmit for the form.

For example, submit button1 -onclick sets global var
whichButton=but ton1.
And in -onSubmit function, I check the value of whichButton, if it is
button1 then I know that all textfields need to be filled, if it is
button2 then I make sure that only the 1 needed textfield is filled.

Thanks again.

al**@paul.rutge rs.edu (Syed Ali) wrote in message news:<30******* *************** ***@posting.goo gle.com>...
Hello,

I have 1 HTML form with 4 submit buttons and 10 textfield entry areas.

If submit button1 is pressed I need to make sure that all 10 textfield
entries have been filled before submitting the form.

If submit button2 is pressed I need to make sure that only textfied1
is filled before submitting the form.

How do I go about doing the above check?

I used -onSubmit with the HTML form tab, but I am not sure how to
check which button was pressed, i.e., how do I reference submit1,
submit2 button in my logic of:
if submit1 then
if all textfields have been completed then
return true
else
return false

I also tried to used -onClick with each Submit button, but returning
false if all textfields have not been filled still causes the form to
get submitted to the CGI script because the HTML form submit itself
has no -onSubmit handler.

THank you!

Jul 20 '05 #8
Syed Ali wrote:
What worked me for me is setting a global var with -onlick on each
submit button and then checking the value of that global var in
-onSubmit for the form.

For example, submit button1 -onclick sets global var
whichButton=but ton1.
And in -onSubmit function, I check the value of whichButton, if it is
button1 then I know that all textfields need to be filled, if it is
button2 then I make sure that only the 1 needed textfield is filled.
There is no need to spoil namespaces. Use `whichbutton' as a property
of a DOM object, e.g. the `HTMLFormElemen t' object itself. Or use the
`value' property of a input[type="hidden"] `HTMLInputEleme nt' object
instead.
[Top post]


Please do not waste scarce resources.
PointedEars
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8052
by: Frances Del Rio | last post by:
I have a form in which submit button is an img.. would like to do it w/a rollover, but can't get rollover to work.. can you do rollovers w/img submit buttons? this is code I have: <input type="image" name="log" src="images/login.gif" value="Submit" alt="Submit" onMouseover = "log.src='images/login-roll.gif'" onMouseout ="images/log.src='login.gif'"> thank you..
7
2777
by: M | last post by:
i have a form which i would like to input different "action" url depending on the button that was clicked. is there a way that javascript can prefill a defined action based on the button pressed? thanks!!!
1
10273
by: Frances Del Rio | last post by:
I have a form in which submit button is an img.. would like to do it w/a rollover, but can't get rollover to work.. can you do rollovers w/img submit buttons? this is code I have: <input type="image" name="log" src="images/login.gif" value="Submit" alt="Submit" onMouseover = "log.src='images/login-roll.gif'" onMouseout ="images/log.src='login.gif'"> thank you..
6
2153
by: stellstarin | last post by:
I have a HTML page containing two submit buttons in the same form.When the form is submitted,I want to know through which submit button the form was submitted. Is there any event or property which identifies this?
1
1952
by: josephChiaWY | last post by:
Hi all, I am a newbie in php. I have met a problem in echoing a few submit buttons using while loop. How do i differentiate which submit button is being click in order to grab the correct data. Below are a part of my codes: while($requestMatch = mysql_fetch_array($friendRequest)){ echo "<table width=425 height=130 border=0>"; echo "<tr>";
2
3720
by: F159753 | last post by:
Hi, I have 2 text box and a "search " button. I would like to check if the text boxes are empty when the search button has been pressed. How should I do that? Regards, FF
3
2500
by: Daniel | last post by:
Hi all, I am using .NET 1.1. I have a form with a cancel button, something like this: <form method="post"....> <input type="submit" value="Submit"> <input type="submit" value="Cancel" id="btnCancel"> </form>
8
1708
by: jodleren | last post by:
Hi It is late and I am tired. I cannot remember how to check which of my buttons on the form was pressed. There are all submit's. Like echo "P=".$_POST; // and eventually using isset() But how was it it was?
3
3799
by: webster5u | last post by:
Hi, i have a question about JavaScript. When we click a submit button from the form with multi-submit button. Can JavaScript detect which submit button has been submit? I make a form with 3 submit button (select, update and delete) and i put validation javascript function in onSubmit event handler. May i apply different validation according to different submit button?
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.