Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP/Javascript event catcher

Reply
Thread Tools

JSP/Javascript event catcher

 
 
morc
Guest
Posts: n/a
 
      02-09-2006
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

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      02-09-2006

"morc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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


 
Reply With Quote
 
 
 
 
morc
Guest
Posts: n/a
 
      02-09-2006
thanks that explains alot.

how do you suggest i should have the javascript reload the page but
also call the jsp method??

 
Reply With Quote
 
morc
Guest
Posts: n/a
 
      02-09-2006
is ther anyway i can call it in maybe form action???

 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      02-09-2006

"morc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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


 
Reply With Quote
 
morc
Guest
Posts: n/a
 
      02-09-2006
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

 
Reply With Quote
 
Hal Rosser
Guest
Posts: n/a
 
      02-10-2006

"morc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone with experience with pod catcher software default Firefox 10 06-27-2006 10:22 PM
website catcher jwaixs Python 9 07-06-2005 04:08 PM
Re: Catcher trollhunter@hanmail.com Digital Photography 0 02-23-2004 01:38 AM
GUI application death catcher? Douglas Alan Python 7 02-20-2004 07:34 PM



Advertisments