JSP/Javascript event catcher

Discussion in 'Java' started by morc, Feb 9, 2006.

  1. morc

    morc Guest

    hi,
    i was wondering how to call a function upon clicking of a button... i
    have abutton that uses some javascript to unhide a div... but at the
    same time i would like it to call a method not part of javascript.

    <form>
    <input type="button" value="Generate Code"
    onClick="display('code');"'<%UserBean.trackModels("n3",user,1);%>'"">
    </form>


    that is the code i tried... the javascript function works properly but
    im unsure how to have the jsp method called.

    i tried a system out println right after the calling trackModels and it
    seems to execute when the page loads rather then when the button is
    clicked. and the trackModels method doesn't get called at all.

    any and all help is appreciated
    thanks alot
    -morc
    morc, Feb 9, 2006
    #1
    1. Advertising

  2. morc

    Oliver Wong Guest

    "morc" <> wrote in message
    news:...
    > hi,
    > i was wondering how to call a function upon clicking of a button... i
    > have abutton that uses some javascript to unhide a div... but at the
    > same time i would like it to call a method not part of javascript.
    >
    > <form>
    > <input type="button" value="Generate Code"
    > onClick="display('code');"'<%UserBean.trackModels("n3",user,1);%>'"">
    > </form>
    >
    >
    > that is the code i tried... the javascript function works properly but
    > im unsure how to have the jsp method called.
    >
    > i tried a system out println right after the calling trackModels and it
    > seems to execute when the page loads rather then when the button is
    > clicked. and the trackModels method doesn't get called at all.
    >
    > any and all help is appreciated
    > thanks alot


    When the page is downloaded, the JSP has finished executing. No
    connection is maintained between the server and the browser. After the JSP
    has finished executing, and the page is downloaded, the browser will parse
    the page, notice the JavaScript, and start running it. Again, the JSP has
    finished executing, so it's too late to try to run further JSP code.

    The only workaround is to have your javascript ask the browser to send a
    new request to the server, where a new invocation of your JSP code will
    occur.

    - Oliver
    Oliver Wong, Feb 9, 2006
    #2
    1. Advertising

  3. morc

    morc Guest

    thanks that explains alot.

    how do you suggest i should have the javascript reload the page but
    also call the jsp method??
    morc, Feb 9, 2006
    #3
  4. morc

    morc Guest

    is ther anyway i can call it in maybe form action???
    morc, Feb 9, 2006
    #4
  5. morc

    Oliver Wong Guest

    "morc" <> wrote in message
    news:...
    > thanks that explains alot.
    >
    > how do you suggest i should have the javascript reload the page but
    > also call the jsp method??


    I don't know much JavaScript. You might want to try asking this question
    on a JavaScript related newsgroup. What you would want to do, at a very high
    level, is to make a new request using JavaScript. Depending on the situation
    and what is possible in JavaScript, you may wish to put information in the
    GET or POST headers to explain to the JSP code exactly what it is you want
    it to do. For example, perhaps pass in the name of the method you want to
    have invoked.

    - Oliver
    Oliver Wong, Feb 9, 2006
    #5
  6. morc

    morc Guest

    anyways thanks for kinda showing me hte light.

    i found my self a solution by makin the button a submit and sending it
    to another jsp page where it runs the method an redirects the user
    back. thanks laot
    morc, Feb 9, 2006
    #6
  7. morc

    Hal Rosser Guest

    "morc" <> wrote in message
    news:...
    > hi,
    > i was wondering how to call a function upon clicking of a button... i
    > have abutton that uses some javascript to unhide a div... but at the
    > same time i would like it to call a method not part of javascript.
    >
    > <form>
    > <input type="button" value="Generate Code"
    > onClick="display('code');"'<%UserBean.trackModels("n3",user,1);%>'"">
    > </form>
    >
    >
    > that is the code i tried... the javascript function works properly but
    > im unsure how to have the jsp method called.
    >
    > i tried a system out println right after the calling trackModels and it
    > seems to execute when the page loads rather then when the button is
    > clicked. and the trackModels method doesn't get called at all.
    >

    Oliver's is right. The javascript executes AFTER it gets to the user's
    browser. The JSP code executed on the server.
    JSP can see what the form element's values are at the time it gets the http
    request (when the web page is called). You can only send another http
    request to the jsp page.
    Maybe you could have the javascript change a form element's value before you
    submit the form so the JSP will respond to it in that way.
    Hal Rosser, Feb 10, 2006
    #7
    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. Douglas Alan

    GUI application death catcher?

    Douglas Alan, Feb 18, 2004, in forum: Python
    Replies:
    7
    Views:
    367
    Douglas Alan
    Feb 20, 2004
  2. jwaixs

    website catcher

    jwaixs, Jul 3, 2005, in forum: Python
    Replies:
    9
    Views:
    1,468
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Jul 6, 2005
  3. robert
    Replies:
    0
    Views:
    307
    robert
    Jun 7, 2006
  4. Adrienne Boswell

    Completely OT - Rolo the Mouse Catcher

    Adrienne Boswell, Jan 10, 2009, in forum: HTML
    Replies:
    10
    Views:
    723
    Neredbojias
    Jan 12, 2009
  5. Chuck

    Podcast catcher in Python

    Chuck, Sep 11, 2009, in forum: Python
    Replies:
    17
    Views:
    472
    Chuck
    Sep 19, 2009
Loading...

Share This Page