get names of buttons

H

Husain

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
 
G

GArlington

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)" .../>
 
S

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>
 
T

Thomas 'PointedEars' Lahn

Husain said:
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
 
H

Husain

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.


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top