• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Attaching an onclick event to Sever Side IMG Tag HTML

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following JavaScript that I compile on the server side then use on JSP form.

However, when I try to add my parameters the event will not fire. I am sure my syntax in not correct.

Server Side code


This is what the HTML looks like:

<img title="Access Activity Log" class="modified20" onclick="genericActivityLog(" src="/QMSWebApp/Images/info[1].jpg" miscdisplay2',1602797735315,'drawmfaial','recseq','l')'="">
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes if that's the Generated HTML, the syntax is a mess. What should it be?

And, there's no such thing as "server side IMG tag" so not sure what this has to do with server side. The JavaScript is executed in the browser. The fact the JS is on a JSP template is irrelevant (unless there are JSP directives involved, which there do not appear to be).
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Yes if that's the Generated HTML, the syntax is a mess. What should it be?



This:

<img title="Access Activity Log" class="modified20" src="/QMSWebApp/Images/info[1].jpg" onclick="genericActivityLog('miscdisplay2',1602797735315,'drawmfaial','recseq','l')">

Bear Bibeault wrote:And, there's no such thing as "server side IMG tag" so not sure what this has to do with server side. The JavaScript is executed in the browser. The fact the JS is on a JSP template is irrelevant (unless there are JSP directives involved, which there do not appear to be).



What I mean is I create the JS string on the server side of the app then pass the string to the client side.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:What I mean is I create the JS string on the server side of the app then pass the string to the client side.


How?

And, if the string is not correct on the backend, that's where it needs to be fixed.

If the string is correct, then at what point, if any, does it get mangled?

If the string is not mangled, then check the usage of the string.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Steve Dyke wrote:What I mean is I create the JS string on the server side of the app then pass the string to the client side.


How?



I assign the string result to a session attribute then use JSTL on the client side to display it.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Steve Dyke wrote:What I mean is I create the JS string on the server side of the app then pass the string to the client side.


How?



I told you wrong, sorry.
I embed the HTML string into a JSON string that is called by jQGrid.

If I put single quotes around the parameter the onclick event will not fire.
If I put double quotes around the parameter the jQGrid displays with parsererror: SyntaxError: Invalid character 200 OK
However, even though the grid does not format correctly the IMG tag shows as expected icon and is clickable and fires the function.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:
I embed the HTML string into a JSON string that is called by jQGrid.

If I put single quotes around the parameter the onclick event will not fire.


It's not at all clear how the JSON blob is related to the link.

Is the string OK in the blob? How is the link formatted using the blob content?
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:


It's not at all clear how the JSON blob is related to the link.

Is the string OK in the blob? How is the link formatted using the blob content?

This is on the Server side of the app:



This is what the JSON Blob looks like(notice the Access Activity Log section - there are double quotes in the function parameter) these are inside the double quotes of the JSON paired string:
This is what is causing the parsererror: SyntaxError: Invalid character 200 OK on the jQGrid. But the double quotes around the function parameter is the only thing that makes the function work.

firstArticleListDataModel: {"userdata": {"editMode":true, "elapsedtime":"0 seconds"}, "rows": [{"site": "<img class='modified20' src='/QMSWebApp/Images/American-flag[1].gif' />", "id": 1602797735315, "actionindex": "<img title='Access Activity Log' class='modified20' onclick='genericActivityLog("miscdisplay2")' src='/QMSWebApp/Images/info[1].jpg' >"}]}
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this to work:

 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note: the "'" were coded as "'"
reply
    Bookmark Topic Watch Topic
  • New Topic