Changing a HTML submit button that requests a Servlet, to an image button? How?

  • Thread starter James Storey via JavaKB.com
  • Start date
J

James Storey via JavaKB.com

I have an HTML page that has a form with submit button, that when pressed,
performs an action upon a Java Servlet and fetches back a relevant result.

htmlPage.html
~~~~~~~~~~~~~
....
<form method="POST" action="/ILS/myServlet">
<input type="submit" value="first action" name="option"/>
<input type="submit" value="second action" name="option"/>
</form>
....

myServlet.java
~~~~~~~~~~~~~~
....
String option = request.getParameter("option");

if (option != null) {
if (option.equals("first action"))
firstMethod();

else if
(option.equals("second action"))
secondMethod();
}

---------------------

I would like to "spice up" the style of button by changing the form button
from an input type of "submit, to a type "image":

<input type="image" src="buttons/action1.gif" value="first action"
name="option" size="20"/>
<input type="image" src="buttons/action2.gif" value="second action"
name="option" size="20"/>

However, upon making the changes, when pressing the button, it results in a
blank page. According to references, 'value' is not a valid attribute of
<input type="image>, therefore the form action is not being performed.

Upon trying this in an alternate browser to MSIE, Mozilla works perfectly.
However, I need this to work for MSIE. Does anyone have a solution to this?
 
K

kaeli

However, upon making the changes, when pressing the button, it results in a
blank page. According to references, 'value' is not a valid attribute of
<input type="image>, therefore the form action is not being performed.

Upon trying this in an alternate browser to MSIE, Mozilla works perfectly.
However, I need this to work for MSIE. Does anyone have a solution to this?

Sure -- I don't rely on the value of the submit button / image.

You can set a hidden form field in the onClick of an image if you REALLY need
it. Although if you just name them different, you won't.

--
 
R

Rivky

You can add an onClick mehod that will submit the form.

ie. <input type="image" src="buttons/action1.gif" value="first action"
name="option" size="20" onclick="submitForm(this);"/>

and then add a script that will sumith the form

function submitForm(form){
form.method='post';
form.action='place your action here';
form.submit();
}
 
J

James Storey via JavaKB.com

How would this be done for a page with multiple forms and submits?

Is there a way to do it without adding any script (JAva or VB) in the HTML
page?
 
T

Thomas Weidenfeller

James said:
[quoted text clipped - 7 lines

What article?

Your very own article.

The "web forum" you are using is actually a gateway to Usenet newsgroups
- but tries very hard to hide that fact. Your own article went out to
Usenet with the Message ID
<[email protected]>. Sad that you can't even
identify your own articles in JavaKB.

JavaKB also cuts out the signatures from Usenet messages, so they are
directly messing with the content of articles which are not their own.
This is a no-no on Usenet, but JavaKB doesn't care. They also cut out
header information, and they are sending all postings to Usenet with the
very same e-mail address. Did you know that you and all other JavaKB
users share the same (e-mail address removed) e-mail address? So someone trying
to send you a private e-mail will most likely not reach you. I have no
idea where mails to you end up, but you might want to ask the operators
of JavaKB what happened to the mail.

I recommend you get a software called a "news reader" and directly
connect to a news server, instead of getting the filtered and altered
groups on JavaKB.

/Thomas
 
C

Chris Uppal

Thomas said:
Did you know that you and all other JavaKB
users share the same (e-mail address removed) e-mail address?

Another side-effect of this is that if any one of the people who post via
JavaKB offends or bores someone else enough for that person to kill-file them,
then /all/ the posters via JavaKB will be suppressed.

E.g. a few weeks ago someone from JavaKB (I forget whom) irritated me, so I
kill-filed them. Only after doing so did I realise that I'd effectively
kill-filed the whole forum. I could go back an un-kill-file them, but I
haven't bothered so far...

-- chris
 
R

RS

Sorry - input boxes should actually pass this.form or the name of the
form (defined in the form tag).

To answer you r Q. if i'm understanding wht you want to do:

one way:
For each <input type=image> you can have a different "onClick(); event
that will do different thing. For Example

<input type="image" src="buttons/action1.gif" value="first action"
name="option" size="20" onclick="postToPage1(this.form)"/>
<input type="image" src="buttons/action2.gif" value="second action"
name="option" size="20"onclick="postToPage2(this.form)"/>

with script:
function postToPage1(form){
form.method='post';
form.action='page1.html';
form.submit();
}

function postToPage2(form){
form.method='post';
form.action='page2.html';
form.submit();
}

I the different accoutn they do are as slight as my example, you can
call one function and just pass another paramter indicating where to
go. ie:

function submitForm(form, location){
form.method='post';
form.action='location';
form.submit();
}

Numerous forms shoulb be irrelevent since you are passing a reference
to the form submitForm(this.form);
This is a reference to the field's form and so in your method when you
write will submit THAT form. alternatively, you could do something like
document.formName.submit() as well.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top