Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display JavaScript image with hyperlink inside a function
    text
    copied!<p>Programming and JavaScript noob here, so I appreciate all the help I can get. I'm using CometChat on my website and having some trouble working with their API's. I don't think it's a matter of the API's, it's more how to implement them. I pulled these lines of code from the CometChat website and more or less cut-n-pasted them into a user's profile page (I actually have a CMS system where I can implement this code on the fly). This bit of code goes on a user's profile page (user with ID number 160881).</p> <pre><code>&lt;a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.chatWith('160881');"&gt;&lt;img src="http://www.wechsupport.com/content/images/chatwithme.png" alt="Click here to chat with me now"&gt;&lt;/a&gt; &lt;script type="text/javascript"&gt; function checkstatus(data) { if (data.s == 'available') { alert('User is online'); } } window.onload = function() { jqcc.cometchat.getUser('160881','checkstatus')}; &lt;/script&gt; </code></pre> <p>When navigating to the user's page, first an alert is displayed stating "User is online". Clicking OK, the alert disappears. Also, an image called CHATWITHME is displayed. That's fine, it works, but it's nasty. What I'd rather do is get rid of the alert all together and just display the CHATWITHME image/link if the user's status comes back as available (as shown in the function called CHECKSTATUS). I was thinking to simply take the A HREF piece and replace the ALERT with it such as this:</p> <pre><code>&lt;script type="text/javascript"&gt; function checkstatus(data) { if (data.s == 'available') { &lt;a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.chatWith('160881');"&gt;&lt;img src="http://www.wechsupport.com/content/images/chatwithme.png" alt="Click here to chat with me now"&gt;&lt;/a&gt;; } } window.onload = function() { jqcc.cometchat.getUser('160881','checkstatus')}; &lt;/script&gt; </code></pre> <p>But this did not work. The alert went away (which is guess is good), but the image/link is not displayed. I have very limited experience working with code and simply don't know how to get the anchor tag to work within the function. I can use whatever help is offered.</p> <p>Thanks!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload