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

get names of buttons

P: n/a
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
Share this Question
Share on Google+
4 Replies


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

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

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.