Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
I have a javascript code that upon successful execution renders a bunch of numbers, e.g:
Code: Select all
<script type="text/javascript">
  showDigits()
</script>

on the other hand I have an image on my site and what i want is it's title attribute to contain the figures outputted by the javascript code e.g:
Code: Select all
<img src="<cms:show image />" alt='' title="<cms:show captured_code" />


What I need is a way to capture the javascript output and save it into a variable that I can then use in the image's title attribute.

:idea:'s??
---
You live many times, but only ever remember your lives.length - 1
---
Image
JavaScript is executed client-side by a visitor's browser. What you are trying to do is not possible because Couch (server-side) has already completed its task and sent the page contents to your browser by the time any JavaScript runs.

What is the purpose of this showDigits function and what value(s) does it return? Depending on the answer to that question, you will want to pursue a Couch/PHP or JavaScript only solution.
cheesypoof wrote: What is the purpose of this showDigits function and what value(s) does it return? Depending on the answer to that question, you will want to pursue a Couch/PHP or JavaScript only solution.


Well it can probably be done by a Couch/PHP code, just that I already had a javascript one in place.
The img I have is actually a graphical representation of my site's total number of hits, i wanted the title iof that image to display (when cursor is hovered over it) that that particular user had visited the page x number of times out of the total number of page hits.

You can view my site here and check the counter at the bottom, above the Copyright
---
You live many times, but only ever remember your lives.length - 1
---
Image
We wouldn't want to cache this, so JavaScript seems to be appropriate. Since you already have jQuery included, we can make use of it:
Code: Select all
$('#counter').attr('title', showDigits());
In this example, the targeted element (the image) has an id of counter. Feel free to modify the selector.
doesn't seem to work, the image currently has title="Total Hits" that I set myself,
I've placed the above code you gave me and altered the id, it isn't working

Code: Select all
<script type="text/javascript">
  $('#counter2').attr('title', insertCounter());
</script>

That's the code i've placed on my page. :(
---
You live many times, but only ever remember your lives.length - 1
---
Image
There are issues with your functions because they do not return values, but write to the document. I'll pm you.
I have no idea what you just said :P
If you check my homepage, your code is working, it's displaying the text i want, only it's not putting it under the TITLE attribute.
---
You live many times, but only ever remember your lives.length - 1
---
Image
7 posts Page 1 of 1