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

Discussion in 'Java' started by James Storey via JavaKB.com, Apr 5, 2005.

  1. 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?

    --
    Message posted via http://www.javakb.com
     
    James Storey via JavaKB.com, Apr 5, 2005
    #1
    1. Advertising

  2. James Storey via JavaKB.com

    kaeli Guest

    In article <>,
    enlightened us with...
    >
    > 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.

    --
    --
    ~kaeli~
    Bakers trade bread recipes on a knead-to-know basis.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, Apr 5, 2005
    #2
    1. Advertising

  3. James Storey via JavaKB.com

    Rivky Guest

    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();
    }
     
    Rivky, Apr 6, 2005
    #3
  4. Re: Changing a HTML submit button that requests a Servlet, to an image button? H

    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?

    --
    Message posted via http://www.javakb.com
     
    James Storey via JavaKB.com, Apr 7, 2005
    #4
  5. Re: Changing a HTML submit button that requests a Servlet, to an image button? H

    What article?

    --
    Message posted via http://www.javakb.com
     
    James Storey via JavaKB.com, Apr 7, 2005
    #5
  6. Re: Changing a HTML submit button that requests a Servlet, to animage button? H

    James Storey via JavaKB.com wrote:
    >
    >
    > 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
    <>. 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? 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

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
     
    Thomas Weidenfeller, Apr 7, 2005
    #6
  7. James Storey via JavaKB.com

    Chris Uppal Guest

    Re: Changing a HTML submit button that requests a Servlet, to an image button? H

    Thomas Weidenfeller wrote:

    > Did you know that you and all other JavaKB
    > users share the same 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
     
    Chris Uppal, Apr 7, 2005
    #7
  8. James Storey via JavaKB.com

    RS Guest

    Re: Changing a HTML submit button that requests a Servlet, to an image button? H

    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.
     
    RS, Apr 8, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russell
    Replies:
    3
    Views:
    6,971
    Lau Lei Cheong
    Jun 24, 2004
  2. Fernando Arámburu

    web requests and mobile requests

    Fernando Arámburu, Apr 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    473
    Joerg Jooss
    Apr 8, 2005
  3. circuit_breaker
    Replies:
    2
    Views:
    2,081
    Jack Jia
    Apr 4, 2004
  4. Replies:
    9
    Views:
    9,748
  5. Replies:
    4
    Views:
    1,248
    Adrienne Boswell
    Mar 23, 2010
Loading...

Share This Page