473,320 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with link counter

I have this code I would like to use as a link counter but it just will not store the number nor increment it. please help. I need this ASAP.



[HTML]
<!-- Start: JAVASCRIPT for Counter -->


<script type="text/javascript">
/* add 1 to the total */
function addItem(theCount){
if(parseFloat(document.getElementById(theCount).in nerHTML) > 0){
document.getElementById(theCount).innerHTML = parseFloat(document.getElementById(theCount).inner HTML) + 1;
}
}
/* removes 1 from total as long as total is above 0
function removeItem(theCount){
if(parseFloat(document.getElementById(theCount).in nerHTML) > 0){
document.getElementById(theCount).innerHTML = parseFloat(document.getElementById(theCount).inner HTML)-1;
}
} */

/* resets all items according the tagToCheck param to 0
function resetAllItems(tagToCheck){
var numElements = document.getElementsByTagName(theCount).length;
var i = 0;
while (i < numElements){
document.getElementsByTagName(theCount)[i].innerHTML = 0;
i++
}
} */

/* post all item counts to your ASP page */
function postItems(){
$count = 0
document.getElementById('MentalHealthManual').valu e = document.getElementById('MentalHealthManual').inne rHTML;
//document.getElementById('txtHam').value = document.getElementById('countHam').innerHTML;
//document.getElementById('txtCola').value = document.getElementById('countCola').innerHTML;
//document.getElementById('frmPostItems').submit();
}
</script>

<!-- END: JAVASCRIPT for Counter -->
<p><a href="http://vaww.st-louis.med.va.gov/training/MH_National_Manual_07_02_08_v2.pdf" onclick="addItem('MentalHealthManual'); return false;"><img src=../employee_news/images/BigNew.gif alt="click to download item" /></a>
<br /><span id="MentalHealthManual" onclick="removeItem('MentalHealthManual');" class="itemCount">0</span> Tuna sandwich</p>[/HTML]
Aug 5 '08 #1
10 1861
acoder
16,027 Expert Mod 8TB
addItem can never increment because the initial value is 0 and you've got a check that the value is greater than 0. Remove the if-condition.

Secondly, removeItem is commented out.
Aug 5 '08 #2
Yes I have many things commented out I just want to increment and for it to stay up. Just as a counter. But I have problems incrementing and making it hold its value. help!
Aug 5 '08 #3
addItem can never increment because the initial value is 0 and you've got a check that the value is greater than 0. Remove the if-condition.

Secondly, removeItem is commented out.
I removed the if statement but the value goes back to 0. I want it to stay and increment. What can I do??
Aug 5 '08 #4
acoder
16,027 Expert Mod 8TB
When you say you want it to increment, do you mean automatically by time (e.g. every second) or do you mean on clicking the link?

Also when you say it goes back to 0, do you mean when you leave the page and come back to it? or do you mean something else?
Aug 6 '08 #5
When you say you want it to increment, do you mean automatically by time (e.g. every second) or do you mean on clicking the link?

Also when you say it goes back to 0, do you mean when you leave the page and come back to it? or do you mean something else?

I want the counter to increment everytime I click on the link. When I click on the pic. it increments to 1 and opens the page I want. But when I go back to the page it resets itself to 0. I want this to increment by 1 everytime I click it.
Aug 6 '08 #6
acoder
16,027 Expert Mod 8TB
You'll need to use cookies to store the number. When you return back to the page, check for the cookie. If it's set, set the counter to the cookie value, otherwise leave it at 0.

To learn how to read, write and delete cookies, see this tutorial.
Aug 6 '08 #7
You'll need to use cookies to store the number. When you return back to the page, check for the cookie. If it's set, set the counter to the cookie value, otherwise leave it at 0.

To learn how to read, write and delete cookies, see this tutorial.

[HTML]

<!-- Start: JAVASCRIPT for Counter -->
<SCRIPT LANGUAGE="JavaScript">
<!--
function nameDefined(ckie,nme)
{
var splitValues
var i
for (i=0;i<ckie.length;++i)
{
splitValues=ckie[i].split("=")
if (splitValues[0]==nme) return true
}
return false
}

function delBlanks(strng)
{
var result=""
var i
var chrn
for (i=0;i<strng.length;++i) {
chrn=strng.charAt(i)
if (chrn!=" ") result += chrn
}
return result
}
function getCookieValue(ckie,nme)
{
var splitValues
var i
for(i=0;i<ckie.length;++i) {
splitValues=ckie[i].split("=")
if(splitValues[0]==nme) return splitValues[1]
}
return ""
}
function insertCounter() {
readCookie()
displayCounter()
}
function displayCounter() {
document.write('<H3 ALIGN="CENTER">')
document.write("You've visited this page ")
if(counter==1) document.write("the first time.")
else document.write(counter+" times.")
document.writeln('</H3>')
}
function readCookie() {
var cookie=document.cookie
counter=0
var chkdCookie=delBlanks(cookie) //are on the client computer
var nvpair=chkdCookie.split(";")
if(nameDefined(nvpair,"pageCount"))
counter=parseInt(getCookieValue(nvpair,"pageCount" ))
++counter
var futdate = new Date()
var expdate = futdate.getTime()
expdate += 3600000 * 24 *30 //expires in 1 hour
futdate.setTime(expdate)

var newCookie="pageCount="+counter
newCookie += "; expires=" + futdate.toGMTString()
window.document.cookie=newCookie
}

// -->
</SCRIPT>
<!-- END: JAVASCRIPT ROUTINES For Counter -->
[/HTML]

I am using this code to cookies but it is another persons work all I want is to display the value where is the value???
Aug 6 '08 #8
acoder
16,027 Expert Mod 8TB
Try using the code in the link and see the example code. To set the value, use setCookie() and to read it, getCookie(). Use something similar to the checkCookie() function onload.
Aug 6 '08 #9
thanks tried it and it came out good.
Aug 7 '08 #10
acoder
16,027 Expert Mod 8TB
Glad to hear it. Post again if you have any more questions.
Aug 7 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Wolfgang Kaml | last post by:
Hello All, I have been researching newsgroups and knowledgebase all morning and not found a solution that would solve the problem I have. I am having an ASP or ASPX web page that implement a...
15
by: sathyashrayan | last post by:
Dear group, The below given link which I want to implement in C. http://online-judge.uva.es/p/v1/100.html The code which I wrote does not even reaches the near to the given problem.(I am...
5
by: garfy | last post by:
Hi i get this error in validation Line 22 column 6: document type does not allow element "title" here. <title>Seo Web Design Los Angeles - Web Design And Search Engine Optimization L ...
6
by: caine | last post by:
I have a clickable calendar, which user can select the day that they want to view the news linking to. My calendar has the clickable event day, but once the user click it, the day selected could...
2
by: r3d dra6on | last post by:
I am not sure where I am going wrong with this. I get a lot of LINK errors, and I am unsure of how to solve the problem with them. Can someone please tell me where I went wrong? #include...
3
by: kennykenn | last post by:
im producing a banner and want the banner to rotate and fade in and out to the next image. i want to link each image to a SEPERATE site! I can get it to work with out the fading effect and can get...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
3
by: kashif73 | last post by:
Hi, I have a database of more than 1000 users. I am sending an email to 50 users at a time using CDO. What i do is get all the email addresses first & then split them into a batch of 50 email...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.