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

get names of buttons

Hello.

I am new to Javascript and JSP. I would like to have multiple submit
buttons in a form. Each button has a different action? How can I go
about doing that? How can I obtain the button's name or id?

Thank you
Apr 11 '08 #1
4 2135
On Apr 11, 9:35 am, Husain <husran...@gmail.comwrote:
Hello.

I am new to Javascript and JSP. I would like to have multiple submit
buttons in a form. Each button has a different action? How can I go
about doing that? How can I obtain the button's name or id?

Thank you
<input type="button" name="???" onclick="alert(this.name)" .../>
Apr 11 '08 #2
SAM
Husain a écrit :
Hello.

I am new to Javascript and JSP. I would like to have multiple submit
buttons in a form. Each button has a different action? How can I go
about doing that? How can I obtain the button's name or id?
Usual way of doing :

- All submit-buttons have same name
- each button has its own value according to some action
- code server-side uses the name of submit button to know
what action to serve (the submit-button's value)
with the other elements of the form
- javascript uses :
1) an onclick attributed to the button
- most simple :
to give the value of button to a global variable
<input type=submit value="Do That" name="send"
onclick="ToDo=this.value">
- or a function to do somethin with the elements of the form
2) the attribute 'onsubmit' given to the tag 'form'
That can give :

<html>
<script type="text/javascript">
var ToDo = '';
function validate () {
return confirm('Ok for this action : '+ToDo+' ?');
}
</script>
<form action="javascript:alert('message sent')"
onsubmit="return validate();">
<p><input type=submit name="send" value="First action"
onclick="ToDo=this.value">
<p><input type=submit name="send" value="Second action"
onclick="ToDo=this.value">
<p><input type=submit name="send" value="Third action"
onclick="ToDo=this.value">
</form>
</html>

--
sm
Apr 11 '08 #3
Husain wrote:
I am new to Javascript and JSP. I would like to have multiple submit
buttons in a form. Each button has a different action?
No, that is not possible. You need to have different forms for different
form actions. However, the server-side resource to receive the form data
as referred to by one form element's `action' attribute can differentiate
between the action to be performed according to the used submit button.
How can I go about doing that? How can I obtain the button's name or id?
Only the activated submit button is included in the list of successful
controls. So you could use the same name and evaluate the different value
server-side. However, it becomes more difficult with automated i18n.

Another approach is to use a different control name for each submit button.
Since only the activated submit button is considered a successful one, you
only get its name in the request and not the names of the other buttons.

This has nothing to do with "Javascript", nor should client-side scripting
be used to resolve it (unless further client-side actions are necessary on
submit.)

BTW, JSP is JavaServer Pages (not JavaScript Pages), which is therefore
off-topic here and on-topic in comp.lang.java.*. Java != JavaScript.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 27 '08 #4
On Apr 14, 7:19 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Husain wrote:
I am new to Javascript and JSP. I would like to have multiple submit
buttons in a form. Each button has a different action?

No, that is not possible. You need to have different forms for different
form actions. However, the server-side resource to receive the form data
as referred to by one form element's `action' attribute can differentiate
between the action to be performed according to the used submit button.
How can I go about doing that? How can I obtain the button's name or id?

Only the activated submit button is included in the list of successful
controls. So you could use the same name and evaluate the different value
server-side. However, it becomes more difficult with automated i18n.

Another approach is to use a different control name for each submit button.
Since only the activated submit button is considered a successful one, you
only get its name in the request and not the names of the other buttons.

This has nothing to do with "Javascript", nor should client-side scripting
be used to resolve it (unless further client-side actions are necessary on
submit.)

BTW, JSP is JavaServer Pages (not JavaScript Pages), which is therefore
off-topic here and on-topic in comp.lang.java.*. Java != JavaScript.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Thank you all for your kind response.
Jun 27 '08 #5

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

Similar topics

7
by: PhilM | last post by:
perhaps I am just a little tired, but I am having trouble with my form buttons. Firstly I name them like this name=\"round".$counter."heats\" which results in variables $round1heats...
7
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically...
9
by: Paul Morrow | last post by:
I have seen the technique where a number of rows in a database are displayed in an html table so that each column of each row is editable. They use a single form surrounding the table, where each...
3
by: larry | last post by:
Hi, I am a newbie to Internet programming. I have some questions about spacing in HTML control names and subsequently being able to access these input elements in JavaScript If you don't have...
11
by: Jon Hoowes | last post by:
Hi, I have inherited some code that has some form elements (radio buttons) that are called "1", "2" etc. for example: <input name="2" type="radio" value="45"> <input name="2" type="radio"...
3
by: Keith Wilby | last post by:
I have a form which allows both form and datasheet views. My question is, is it possible to control the field (column) names in datasheet view? What happens at the moment is that the name is...
3
by: MLH | last post by:
Generally, I do not monkey with renaming controls on forms whose name, by default, matches the name of their related table fields. But I noticed the following today If IsNull(Me!VColor) Then...
7
by: Matt | last post by:
Hi all, I'm trying to create a system where it reads a number of records from a database and then creates a row in the GUI that contains a single field from the database and a button that has a...
6
by: likhin M | last post by:
Hi everyone, I am developing a webpage using only javascript.And I am dynamically creating buttons inside javascript as follows document.write('<button name=""...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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
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...

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.