473,403 Members | 2,071 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,403 software developers and data experts.

Getting button id in JS

Hi,

I am working on Struts/HTML/Javascript application.

Have 2 buttons on the page, Save and Cancel,
both are supposed to bring me to the same page,
but Save also performs validation, and Cancel - should not.
Both buttons are of Submit type and have same name ("SubmitValue"), e.g.:
<input type="submit" id="SaveBtn" name="submitValue" value="Save">

So how do I distinguish which button was clicked on Submit for the form:
<form name="input" onClick="if (??? = "SaveBtn") return validate()" >,
how do I capture that id=SaveBtn in JavaScript ?

Thank you in advance,
Oleg.
Nov 7 '07 #1
3 6506
On Nov 7, 2:50 pm, Oleg Konovalov <okono...@verizon.netwrote:
Hi,

I am working on Struts/HTML/Javascript application.

Have 2 buttons on the page, Save and Cancel,
both are supposed to bring me to the same page,
but Save also performs validation, and Cancel - should not.
Both buttons are of Submit type and have same name ("SubmitValue"), e.g.:
<input type="submit" id="SaveBtn" name="submitValue" value="Save">

So how do I distinguish which button was clicked on Submit for the form:
Change either the name or value of one of the buttons so your server
can tell which one was clicked.
--
Rob

Nov 7 '07 #2
RobG wrote:
On Nov 7, 2:50 pm, Oleg Konovalov <okono...@verizon.netwrote:
>Hi,

I am working on Struts/HTML/Javascript application.

Have 2 buttons on the page, Save and Cancel,
both are supposed to bring me to the same page,
but Save also performs validation, and Cancel - should not.
Both buttons are of Submit type and have same name ("SubmitValue"), e.g.:
<input type="submit" id="SaveBtn" name="submitValue" value="Save">

So how do I distinguish which button was clicked on Submit for the form:

Change either the name or value of one of the buttons so your server
can tell which one was clicked.
--
Rob
Values arre different, one is "Save", other one is "Cancel"
How do I get it there:
<form name="input" onClick="if (??? = "SaveBtn") return validate()" ?
Nov 7 '07 #3
On Nov 7, 2:02 pm, Oleg Konovalov <okono...@verizon.netwrote:
RobG wrote:
On Nov 7, 2:50 pm, Oleg Konovalov <okono...@verizon.netwrote:
Hi,
I am working on Struts/HTML/Javascript application.
Have 2 buttons on the page, Save and Cancel,
both are supposed to bring me to the same page,
but Save also performs validation, and Cancel - should not.
Both buttons are of Submit type and have same name ("SubmitValue"), e.g.:
<input type="submit" id="SaveBtn" name="submitValue" value="Save">
So how do I distinguish which button was clicked on Submit for the form:
Change either the name or value of one of the buttons so your server
can tell which one was clicked.
--
Rob

Values arre different, one is "Save", other one is "Cancel"
How do I get it there:
<form name="input" onClick="if (??? = "SaveBtn") return validate()" ?
You got it completely wrong. First of all, you don't put <form
onclick..but <input type="submit" onclick...>. Here's a short
example (untested) how you should go:
<script type="text/javascript">
function save()
{
// check everything
if ( everythingOk )
return true;
return false;
}

function cancel()
{
return true;
}
</script>
<form action="...">
<input type="submit" value="Save" name="save" onclick="return
save()" />
<input type="submit" value="Cancel" name="cancel" />
</form>

If you don't need any validation on cancel, then just don't handle it
in javascript,
but let it be a normal submit button. save(), however, should do the
validation, and if it
returns false, then submitting won't happen. If it returns true, it
will.

Now, what I really don't understand - why did you put both buttons
have the same name? If you let
them have the same name, then the server-side script won't be able to
know what button was pressed.
Having them have different names, like above, the server-side script
will be able to distinguish which
button was pressed and act accordingly.

Nov 7 '07 #4

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

Similar topics

2
by: Timo J | last post by:
Hi - Im sitting and trying to understand this OOP - and need to create a class wich can do the following.. ShowBlocks() - Displays the data wich is inside it - If empty creates a form wich sends...
8
by: Harlin Seritt | last post by:
I have the following script. Two widgets call the same function. How can I tell inside of the called function which button called it?: def say_hello(): print 'hello!' print widget root =...
0
by: Curtis | last post by:
I am having some trouble getting my common compenent to be able to refresh and I am hoping someone will be able to tell me what I am missing. To simply things I have created a solution with a...
7
by: gerryLowry::Ability Business Computer Services {KC | last post by:
"Getting Back Your Visual Basic 6.0 Goodies" by Billy Hollis, 2003-5-14, states: "Getting a Forms Collection Visual Basic 6.0 developers are often fond of looping through the currently loaded...
0
by: Erik | last post by:
Why isn't my update method getting called? Pasted below is an aspx from a 1.1 application I'm working on. It has two textboxes and a button for inserting data into the database, and a datagrid...
1
by: BrainTop | last post by:
This is driving me nuts for last one week. Appreciate any assistance. I have ASP.NET web application with many pages. Some of them post back to itself and then links to another page. Everything...
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
1
by: imranabdulaziz | last post by:
Dear All, I am mess with one situation let me explain the scenario. I am making search form where I display 15 field in checkboxlist and user select one or two or three or any no to all field....
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
4
by: SAL | last post by:
Hello, I'm working, basically my first, AJAX page and am having a few problems. One is that the Click event for a button I have in UpdatePanel1 is not getting called. I've tried with the button...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.