Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

JSP/Javascript event catcher

Thread view: 
morc - 09 Feb 2006 19:36 GMT
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
Oliver Wong - 09 Feb 2006 19:45 GMT
> hi,
> i was wondering how to call a function upon clicking of a button... i
[quoted text clipped - 15 lines]
> 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
morc - 09 Feb 2006 19:56 GMT
thanks that explains alot.

how do you suggest i should have the javascript reload the page but
also call the jsp method??
morc - 09 Feb 2006 19:59 GMT
is ther anyway i can call it in maybe form action???
Oliver Wong - 09 Feb 2006 20:07 GMT
> 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
morc - 09 Feb 2006 21:33 GMT
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
Hal Rosser - 10 Feb 2006 01:00 GMT
> hi,
> i was wondering how to call a function upon clicking of a button... i
[quoted text clipped - 12 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.