/    Sign up×
Community /Pin to ProfileBookmark

Mouse Click Counts

My attachment displays todays date. Below it is a ‘next week’ button which should give next week’s date when pressed once. When once again should give date after 2 weeks and so on.

My logic is to count no. of clicks on the button in function clickCount(f) and give this value to function updateFields(n) to give next weeks date.

But my program doesn’t run. ?

Help !

Here’s my code. I have even attached it !

[code]

<html>
<head>
<script type=”text/javascript”>

var count=0;
function clickCount(f) {
count += 1;
f.value = count;
}

function makeArray0() {
for (i = 0; i<makeArray0.arguments.length; i++)
this[i] = makeArray0.arguments[i];
}

var days = new makeArray0(‘Sunday’,’Monday’,’Tuesday’,’Wednesday’,’Thursday’,’Friday’,’Saturday’);

function makeDate(x) {
var days = new makeArray0(‘Sunday’,’Monday’,’Tuesday’,’Wednesday’,’Thursday’,’Friday’,’Saturday’);
now = new Date();
now = new Date(now.getFullYear(),now.getMonth(),now.getDate(),0,0,0); // midnight
var theDay = new Date(now.getTime()+(x*24*60*60*1000));
return days[theDay.getDay()] + ‘ ‘ + theDay.getDate() + ‘-‘ + (theDay.getMonth()+1) + ‘-‘ + theDay.getFullYear();
}

function updateFields(n) {
for(var i=0; i <= 6; i++) {
document.getElementById(“date”+i).innerHTML = makeDate(i+n);
}

}

</script>
<head>

<body>
<table width=”146″ height=”81″ border=”1″ align=”center”>
<tr>
<td width=”92″ id=”date1″><script type=”text/javascript”>document.write(makeDate(0));</script></td>
</tr>
<tr>
<td align=”center”>
<form>
<input type=”button” value=”Next Week” onClick=”clickCount(form)”>
<a href=”#” onclick=”updateFields(7 * clickCount(form));return false;”></a>
<form>
</td>
</tr>
</table>
</body>
</html>

[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameMar 10.2009 — Best to just show you one way I would do it, if questions on it, ask more.
[code=html]<html>
<head>
<script type="text/javascript">

var WEEK_GET = { //a single global object, within it's method's 'this' will refer to the WEEK_GET object itself
count : 0,

makeDate : function () {
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var now = new Date();
var futureWeek = new Date(now.getTime() + (this.count * 604800000)); //86400000 ms per day * 7 = 604800000 ms per week
return days[futureWeek.getDay()] + ' ' + months[futureWeek.getMonth()] + '-' + futureWeek.getDate() + '-' + futureWeek.getFullYear();
},
update : function (override) {
if (!override) {
this.count++;
}
document.getElementById("date1").innerHTML = this.makeDate();
},
reset : function () {
this.count = 0;
this.update(1);
}
};

window.onload = function () {
WEEK_GET.update(1);
};

</script>
<head>

<body>
<table width="200" height="81" border="1" align="center">
<tr>
<td id="date1" align="center"> </td>
</tr>
<tr>
<td align="center">
<button type="button" onclick="WEEK_GET.update();">Future Week</button><br>
<button type="button" onclick="WEEK_GET.reset();">Reset</button>
</td>
</tr>

</table>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@omnicityMar 10.2009 — The first thing that stands out is the line:

[CODE]f.value = count;[/CODE]

since f refers to your form, setting the value is a little strange - did you mean to set the value of a field in your form, because I notice that there are no fields that you [I]could [/I] set!
×

Success!

Help @naash spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...