• Post Reply Bookmark Topic Watch Topic
  • New Topic

onclick()...

 
bala chidambaram
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai

Can i call a 'java' function defined in the current file by 'onclick()'?
Thank u.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. At least not a server-side function. Are you asking about an Applet method?
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are basically calling a onclick or onchange method which likely will be processed inside a script(like Javascript).
In that case you can access server stuff that is available for the purpose of checking values. You can not change them. But you can change the rendering of the current page using something like document.all...
Dan.
 
bala chidambaram
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai
Thank u for ur response.
What i need is,

on executing a 'select' command i will have set records selected as a result. now i need read one by one on clicking a button.

suggestions are welcome
thank u.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In that case you can access server stuff that is available

I'm not sure if I'm reading this correctly, but if I am then it is not correct. There is no facility to access server-side content from Javascript. Could you elaborate what you meant?
The only way you can access server-side content is either to have pre-loaded it into Javascript variables when the page was being constructed, or to submit the normal request/response cycle. There are techniques to do this without refreshing the current page (e.g. submit into an invisible iframe), but submitting a request is the only way to initiate server contact.
 
bala chidambaram
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai bear

Thank u for ur response

I have a jsp file containing some sql command. on execution i will have some records selected. Those will be seen by putting them in 'while' loop. this is done usually. what i want know i whether i can view the record one by one as done VB using movenext,moveprevious and so on on clicking a button in the jsp page.
From our friends response i could understand that the content is generated in the server which then passed to browser.
suggestions are welcome.
thank u
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well following is code from my application inside a java script function.
It sure uses scritlet and accesses a value. same way you can access a list that is available on the server.We for sure can not initiate any action on the server side though.
document.all["<%=inputFieldName%>"].value = strXYZ;
Dan
 
bala chidambaram
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai daniel,
I cannot understand what do u say?
we cannot have a '<%...%>' within java script, am i right?
if so what do u coming to say?
thank u
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as long as you saved the resultset as a hidden or part of the document, you can access it as shown in my code example that is coming right out of a file I am working on.
Dan.
 
bala chidambaram
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dan
would u explain me with a small example?

thank u
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you perform a View Source on the page, you will see that all this has done is to substitue the scipting expression with a string value. This happens on the server at page construction time. My point is, once the page is delivered to the browser, no further server-side access is possible unless a new request is submitted. (This is the sort of thing I meant by "to have pre-loaded it into Javascript variables when the page was being constructed," in an earlier reply).
we cannot have a '<%...%>' within java script, am i right?

You can but it doesn't make much sense. The Java within the scriplet gets executed on the server and does not propogate to the page. However, scripting expressions (<%= ... %>) can be used to build up the Javascript that will be sent to the browser in a dynamic fashion. In any case, it all boils down to the fact that no Java is ever sent to (or is accesible from) the browser... just the result of running Java on the server in order to format the HTML/Javascript that will be sent to the browser.
[ February 27, 2004: Message edited by: Bear Bibeault ]
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recently worked on a similar issue. It came down to the simple fact that, as Bear stated, once the page is delivered to the client machine, all the Java code has already executed, and you're simply viewing the output. Now, in our case, we had a dropdown menu of employee names, but we also wanted the client to be able to rollover, or click on a name, and view that employee's information. Two solutions came to mind:
  • when the onClick() or mouseOver() occurs, send a new request to the server, gather the selected employee's info, and return the response
  • or
  • dump each employee's info into javascript objects, enabling client-side processing of employee records

  • It can be a muddy area, a tradeoff between the overhead of creating javascript objects to contain employee record information, versus the overhead of the trips back and forth to the server each time a user wants to view an employee record. We basically went the javascript route because:
  • the user was likely to view many employees
  • employee records were rather simple and did not require much memory
  • "scrolling" through employee records was processed on the client-side, rather than the server-side

  • All in all, it worked out rather well.
    WS
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!