...

View Full Version : Search & Replace an onclick Event



ChuckLew
05-11-2009, 05:49 PM
OK, here is a sample of the code I'm trying to look at and then change:


<td class=ms-cal-topday onmouseover="this.className = 'ms-cal-topdayover';" onmouseout="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('4\u002f26\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('4\u002f26\u002f2009','Day');" tabindex=2 >26</a></div></td>

We're looking at a cell from a calendar, so I have several similar cells. The information in the "MoveToViewDate" function is dynamic. However, I need to replace the function with a standard link using the information it displays. I can do that just fine on the href of the anchor tags like so:


var aForward=document.getElementsByTagName('a');
for(var i=0;i<aForward.length;i++){
aForward[i].href&&aForward[i].href.match(/javascript:MoveToViewDate\(\'([^']+)\',\'Day\'\);/)?aForward[i].href=aForward[i].href.replace(/javascript:MoveToViewDate\(\'([^']+)\',\'Day\'\);/g,'..\u002fLists\u002fCalendar\u002fcalendar.aspx?$1&CalendarPeriod=Day'):null;
}

When I try to do the same thing on the onclick event of the td tags, though, I get errors. Here is what I am trying:


var tdForward=document.getElementsByTagName('td');
for(var i=0;i<tdForward.length;i++){
tdForward[i].onclick&&tdForward[i].onclick.match(/MoveToViewDate\(\'([^']+)\',\'Day\'\);/)?tdForward[i].onclick=tdForward[i].onclick.replace(/MoveToViewDate\(\'([^']+)\',\'Day\'\);/g,'window.location='..\u002fLists\u002fCalendar\u002fcalendar.aspx?$1&CalendarPeriod=Day''):null;
}

I think this has something to do with the nature of onclick events, but have been able to figure anything out. What do I need to do rewrite the onclick event on each of the td tags using part of the info they already contain?

Thanks in advance.

randomuser773
05-11-2009, 07:10 PM
An event handler isn't a string, try

tdForward[i].onclick.toString().match(........) or preferably

tdForward[i].onclick.toString().replace(/[\n\r]/g, "").match(........)

ChuckLew
05-11-2009, 07:50 PM
Randomuser773, thanks for the quick response. I think I must be missing something fundamental. This is how I interpreted your suggestion:


function CalLinkForward(){
var aForward=document.getElementsByTagName('a');
for(var i=0;i<aForward.length;i++){
aForward[i].href&&aForward[i].href.match(/javascript:MoveToViewDate\(\'([^']+)\',\'Day\'\);/)?aForward[i].href=aForward[i].href.replace(/javascript:MoveToViewDate\(\'([^']+)\',\'Day\'\);/g,'..\u002fLists\u002fCalendar\u002fcalendar.aspx?$1&CalendarPeriod=Day'):null;
}
var tdForward=document.getElementsByTagName('td');
for(var i=0;i<tdForward.length;i++){
tdForward[i].onclick.toString().replace(/[\n\r]/g, "window.location='..\u002fLists\u002fCalendar\u002fcalendar.aspx?$1&CalendarPeriod=Day';").match(/MoveToViewDate\(\'([^']+)\',\'Day\'\);/)
}
}

Unfortunately, I'm still not getting anywhere. I'm using the Firefox plugin "Firebug" to help me figure things out, and I see the error says, "tdForward[i].onclick is undefined." What am I missing here?

randomuser773
05-11-2009, 08:52 PM
I'm using the Firefox plugin "Firebug" to help me figure things out, and I see the error says, "tdForward[i].onclick is undefined." What am I missing here?How exactly are the onclick handlers being applied? If you're attaching listeners rather than handlers then it's not going to work.

ChuckLew
05-11-2009, 09:13 PM
Thanks again for replying. I'm afraid I've reached the end of my knowledge on this one (I'm obviously a bit new to this). The page is rendered using MS SharePoint, and I couldn't really tell you if they are using listeners rather than handlers. Is they a quick way for me to figure that out?

I had another thought though, to search all td tags for "/onclick=\"MoveToViewDate\(\'([^']+)\',\'Day\'\);\"/ and rewriting that with innerHTML instead of looking for the onclick attribute. Do you think that could solve my problem?

ChuckLew
05-12-2009, 04:42 PM
I'm still trying to figure this one out. If anyone can help me understand what I missing here, it would be appreciated.

ChuckLew
05-12-2009, 08:10 PM
OK, so I've been kicking this around a bit more, and believe me I'm learning more and more by the second. Here is what I've come up with so far:


<script type="text/javascript">
function CalLinkForward(){
var aForward=document.getElementsByTagName('a');
for(var i=0;i<aForward.length;i++){
aForward[i].href&&aForward[i].href.match(/javascript:MoveToViewDate\(\'([^']+)\',\'Day\'\);/)?aForward[i].href=aForward[i].href.replace(/javascript:MoveToViewDate\(\'([^']+)\',\'Day\'\);/g,'..\u002fLists\u002fCalendar\u002fcalendar.aspx?$1&CalendarPeriod=Day'):null;
}

var table=document.getElementById('CalViewTable1');
var tdForward=table.getElementsByTagName('td');
for(var i=0;i<tdForward.length;i++){
var getonclick = tdForward[i].getAttribute('onclick');
var re = new RegExp (/MoveToViewDate\(\'([^']+)\',\'Day\'\);/);
var myArray = re.exec(getonclick);
if ( myArray != null) {
var dateClip = new Array(myArray[1]);
//document.write(dateClip + " . . . look here at $1 FireFox show all of them, IE only shows the first one" + "<BR>")
tdForward[i].onclick = ChangeOnClick;
}
}

function ChangeOnClick() {
window.location='..\u002fLists\u002fCalendar\u002fcalendar.aspx?' + dateClip + '&CalendarPeriod=Day'
}
}
</script>

I hope I'm not heading down the wrong path here. I think I very close, but I'm not quite there yet. The anchor tags were already working and that hasn't changed. This is solving the problem of finding the info I wanted from each of the onclick events. My stumbling block now is that this code only places the last "dateClip" that is found instead of the one it found for each td tag. I'm not sure how to store the variables that I'm getting in their own parallel array, so that I can call the in sequence. Can anyone help, with this last step?

DrFish
05-13-2009, 03:56 PM
Hello ChuckLew,

In the code fragment below, you are only making a reference to ChangeOnClick function, you are not actually assigning an "instance" of it to each onclick event.



var dateClip = new Array(myArray[1]);
//document.write(dateClip + " . . . look here at $1 FireFox show all of them, IE only shows the first one" + "<BR>")
tdForward[i].onclick = ChangeOnClick;



The function ChangeOnClick itself is called only on the onclick event, and this happens after you have assigned the current value of dateClip, which happens to be the last TD in the loop.

What you need to do is to use the inline function call:



tdForward[i].onclick = function() {
window.location='../Lists/Calendar/calendar.aspx?' + dateClip + '&amp;CalendarPeriod=Day';
}


be sure you define dateClip somewhere before the loop with
var dateClip = ...;

I'm working on a similar issue, only on mine, I just have to replace one part of the string of an onclick value whose structure I do not know.

DrFish
05-13-2009, 03:58 PM
and something else:

you can log the hell out of your code using firebug's
console.log(string) javascript method. Just use it among your code.
console.dir(object) gives you an outline of an object with all its properties and methods.

See the documentation for details: http://getfirebug.com/console.html

ChuckLew
05-13-2009, 06:43 PM
DrFish, Thank you for your help. I think I understand the need to rewrite the onclick with an inline function. What I don't understand is how to define dateClip before the loop when it is based (indirectly) on tdForward[i].

Here is the code the way I have it now. I have made some regex alteration that I realized were needed to format the links correctly. The concept hasn't changed though, and I am still getting the last onclick's info for everything.


<script type="text/javascript">
function CalLinkForward(){
var aForward=document.getElementsByTagName('a');
for(var i=0;i<aForward.length;i++){
aForward[i].href&&aForward[i].href.match(/javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/)?aForward[i].href=aForward[i].href.replace(/javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/g,'Lists\/Calendar\/calendar.aspx?CalendarDate=$1/$2/$3&CalendarPeriod=Day'):null;
}

var table=document.getElementById('CalViewTable1');
var tdForward=table.getElementsByTagName('td');
for(var i=0;i<tdForward.length;i++){
var getonclick = tdForward[i].getAttribute('onclick');
var re = new RegExp (/MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/);
var myArray = re.exec(getonclick);
if ( myArray != null) {
var dateClip = myArray[1] + "/" + myArray[2] + "/" + myArray[3];
//document.write(dateClip + " . . . look here at $1 FireFox show all of them, IE only shows the first one" + "<BR>")
tdForward[i].onclick = function() {window.location='Lists\/Calendar\/calendar.aspx?CalendarDate=' + dateClip + '&CalendarPeriod=Day';}
}
}
}
</script>

Oh, and thanks for the Firebug tip as well.

DrFish
05-13-2009, 06:50 PM
The following line seemed suspicious to me.

var getonclick = tdForward[i].getAttribute('onclick');

Seems you're assigning to getonclick the reference to the onclick event.

How about changing that to

var getonclick = tdForward[i].getAttribute('onclick').toString();

Sorry don't have the time to check if it works.

ChuckLew
05-13-2009, 07:29 PM
I appreciate the thought you've given this. When I tried your suggestion (adding ".toString()" to the getonclick equation), I get this error "'getAttribute(...)' is null or not an object." Of course, then I don't get any values for "dateClip."

ChuckLew
05-14-2009, 02:47 PM
Ok, so here is where I am now. I've tried a bunch of these helpful ideas, and although I am making some progress, I haven't really achieved the goal yet. By commenting and uncommenting a couple of lines, I am able to notice some rather peculiar behaviors. Can any of you take a look, and help me understand what I'm looking at? Here is the code I'm working with the commented line left in for testing:


<script type="text/javascript">
function CalLinkForward(){
var aForward=document.getElementsByTagName('a');
for(var i=0;i<aForward.length;i++){
aForward[i].href&&aForward[i].href.match(/javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/)?aForward[i].href=aForward[i].href.replace(/javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/g,'Lists\/Calendar\/calendar.aspx?CalendarDate=$1/$2/$3&CalendarPeriod=Day'):null;
}
var table=document.getElementById('CalViewTable1');
var tdForward=table.getElementsByTagName('td');
for(var i=0;i<tdForward.length;i++){
var getonclick = tdForward[i].getAttribute('onclick');
//var getonclick = tdForward[i].getAttribute('onclick').toString;
//var getonclick = tdForward[i].getAttribute('onclick').toString();
var re = new RegExp (/MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/);
var myArray = new Object();
myArray[i] = re.exec(getonclick);
if ( myArray[i] != null) {
var dateClip = new Object();
dateClip[i] = myArray[i][1] + "/" + myArray[i][2] + "/" + myArray[i][3];
//document.write(dateClip[i] + "<BR>");
//var dateClip = myArray[1] + "/" + myArray[2] + "/" + myArray[3];
document.write("tdForward[" + i + "] . . " + dateClip[i] + " . . look here at dateClip; FireFox show all of them, IE only shows the first one" + "<BR>");
//document.write("tdForward[" + i + "] . . " + dateClip[187] + " . . look here at dateClip[187]; FireFox show it but the others are \"undefined\" : IE has no change" + "<BR>");
//tdForward[i].onclick = function() {window.location='Lists\/Calendar\/calendar.aspx?CalendarDate=' + dateClip[i] + '&CalendarPeriod=Day';};
}
}
}
</script>

I'm not sure why I didn't post this code before but if it helps anyone I've stripped the code from the actual page down to just the area I'm trying to change (and then some to make it less than 20000 characters). Here is a full HTML page that I've been using to test this out:


<HTML>
<HEAD>
<title>Celendar Test</title>
<script type="text/javascript">
function CalLinkForward(){
var aForward=document.getElementsByTagName('a');
for(var i=0;i<aForward.length;i++){
aForward[i].href&&aForward[i].href.match(/javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/)?aForward[i].href=aForward[i].href.replace(/javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/g,'Lists\/Calendar\/calendar.aspx?CalendarDate=$1/$2/$3&CalendarPeriod=Day'):null;
}
var table=document.getElementById('CalViewTable1');
var tdForward=table.getElementsByTagName('td');
for(var i=0;i<tdForward.length;i++){
var getonclick = tdForward[i].getAttribute('onclick');
//var getonclick = tdForward[i].getAttribute('onclick').toString;
//var getonclick = tdForward[i].getAttribute('onclick').toString();
var re = new RegExp (/MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/);
var myArray = new Object();
myArray[i] = re.exec(getonclick);
if ( myArray[i] != null) {
var dateClip = new Object();
dateClip[i] = myArray[i][1] + "/" + myArray[i][2] + "/" + myArray[i][3];
//document.write(dateClip[i] + "<BR>");
//var dateClip = myArray[1] + "/" + myArray[2] + "/" + myArray[3];
document.write("tdForward[" + i + "] . . " + dateClip[i] + " . . look here at dateClip; FireFox show all of them, IE only shows the first one" + "<BR>");
//document.write("tdForward[" + i + "] . . " + dateClip[57] + " . . look here at dateClip[57]; FireFox show it but the others are \"undefined\" : IE has no change" + "<BR>");
//tdForward[i].onclick = function() {window.location='Lists\/Calendar\/calendar.aspx?CalendarDate=' + dateClip[i] + '&CalendarPeriod=Day';};
}
}
}
</script>
<style>
.ms-cal-topday {background-color:#FFCC66;}
</style>
</HEAD>
<BODY onLoad="CalLinkForward();">
<table border=0 width=100% id="CalViewTable1" style="border-collapse: collapse" cellpadding=0>
<tr>
<td class="ms-calheader"><IMG SRC="/_layouts/images/blank.gif" width=742 height=1 alt=""></td>
</tr>
<tr>
<td class="ms-calheader"><table border="0" width="100%" cellspacing="1" cellpadding="0" id="CalViewTable12" style="border-collapse: collapse">
<tr>
<td nowrap><div class="ms-cal-navheader" nowrap> <a href="javascript:MoveToViewDate('4\u002f8\u002f2009', null);" tabindex=1 style="visibility:visible" accesskey="["> <img border="0" src="/_layouts/images/prevbuttonltr.gif" width="15" height="15" alt="Previous Month" ></a> <a href="javascript:MoveToViewDate('6\u002f8\u002f2009', null);" tabindex=1 style="visibility:visible" accesskey="]" > <img border="0" src="/_layouts/images/nextbuttonltr.gif" width="15" height="15" alt="Next Month" ></a> &nbsp;May, 2009&nbsp; </div></td>
<td>&nbsp;</td>
<td class="ms-cal-nav-buttonsltr"><span id=ExpandAllId dir="ltr"> <a href="javascript:" class="ms-cal-nav" onClick="javascript:GetMonthView('1111111');return false;" tabindex=1 accesskey="X" nowrap ><NOBR>Expand All</NOBR></a> </span> &nbsp; <span id=CollapseAllId dir="ltr"> <a href="javascript:" class="ms-cal-nav" onClick="javascript:GetMonthView('0000000');return false;" tabindex=1 accesskey="P" nowrap ><NOBR>Collapse All</NOBR></a> </span> <span> &nbsp;|</span> <span> &nbsp; <span class="ms-cal-nav" dir="ltr"> <a id="dayTabLinkId"
href="javascript:MoveView('day');"
accesskey="." tabindex=1 > <img src="/_layouts/images/day.gif"
border=0
width="16"
height="15"
alt=''
> Day </a> </span> &nbsp; <span class="ms-cal-nav" dir="ltr"> <a id="weekTabLinkId"
href="javascript:MoveView('week');"
accesskey="-" tabindex=1 > <img src="/_layouts/images/week.gif"
border=0
width="16"
height="15"
alt=''
> Week </a> </span> &nbsp; <span class="ms-cal-navselected" dir="ltr"> <a id="monthTabLinkId"
href="javascript:MoveView('month');"
accesskey="=" tabindex=1 > <img src="/_layouts/images/month.gif"
border=0
width="16"
height="15"
alt=''
> Month </a> </span> </span> </td>
</tr>
</table></td>
</tr>
<tr>
<td><table width=100% class=ms-cal-gempty cellpadding=0 cellspacing=2 summary="Monthly graphical Calendar View">
<TR>
<td class=ms-cal-weekempty >&nbsp;</td>
<td class=ms-cal-weekempty >&nbsp;</td>
<th scope="col" class=ms-cal-weekname ><div align=center class=ms-cal-weekday>&nbsp;Sunday&nbsp;</div></th>
<th scope="col" class=ms-cal-weekname ><div align=center class=ms-cal-weekday>&nbsp;Monday&nbsp;</div></th>
<th scope="col" class=ms-cal-weekname ><div align=center class=ms-cal-weekday>&nbsp;Tuesday&nbsp;</div></th>
<th scope="col" class=ms-cal-weekname ><div align=center class=ms-cal-weekday>&nbsp;Wednesday&nbsp;</div></th>
<th scope="col" class=ms-cal-weekname ><div align=center class=ms-cal-weekday>&nbsp;Thursday&nbsp;</div></th>
<th scope="col" class=ms-cal-weekname ><div align=center class=ms-cal-weekday>&nbsp;Friday&nbsp;</div></th>
<th scope="col" class=ms-cal-weekname ><div align=center class=ms-cal-weekday>&nbsp;Saturday&nbsp;</div></th>
</TR>
<TR>
<td class=ms-cal-weekempty >&nbsp;</td>
<td class=ms-cal-weekempty >&nbsp;</td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('4\u002f26\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('4\u002f26\u002f2009','Day');" tabindex=2 >26</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('4\u002f27\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('4\u002f27\u002f2009','Day');" tabindex=3 >27</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('4\u002f28\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('4\u002f28\u002f2009','Day');" tabindex=4 >28</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('4\u002f29\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('4\u002f29\u002f2009','Day');" tabindex=5 >29</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('4\u002f30\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('4\u002f30\u002f2009','Day');" tabindex=6 >30</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f1\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f1\u002f2009','Day');" tabindex=7 >1</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f2\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f2\u002f2009','Day');" tabindex=8 >2</a></div></td>
</TR>
<TR>
<td class=ms-cal-weekempty rowspan=6 >&nbsp;</td>
<th scope="row" class=ms-cal-week onMouseOver="this.className='ms-cal-weekselected';" onMouseOut="this.className='ms-cal-week';" rowspan=6 title="April 26 - May 02" onClick="javascript:MoveToViewDate('4\u002f26\u002f2009','Week');" ><div class=ms-cal-weekbox> <a href="javascript:MoveToViewDate('4\u002f26\u002f2009','Week');" tabindex=1 title="April 26 - May 02" ><img border=0 src='/_layouts/images/blank.gif' class='ms-cal-blankimage' alt='April 26 - May 02'></a></div></th>
</TR>
<TR>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-workitem rowspan=3 ><div class="contB" dir="" >
<table border="0" width="100%" cellspacing=0 cellpadding=0 dir="" >
<tr>
<td class="ms-cal-defaultbgcolor"
onmouseover="this.className='ms-cal-defaultbgcolorsel';"
onmouseout="this.className='ms-cal-defaultbgcolor';"
href="/crmc/1200/Lists/Calendar/DispForm.aspx?ID=4.0.2009-05-01T00:00:00Z"
ONCLICK="GoToLink(this);return false;" target="_self"
><a onFocus="OnLink(this)"
href="/crmc/1200/Lists/Calendar/DispForm.aspx?ID=4.0.2009-05-01T00:00:00Z"
ONCLICK="GoToLink(this);return false;" target="_self"
tabindex=7
> • </a> </td>
</tr>
</table>
</div></TD>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-nodataMid >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-nodataBtm2 >&nbsp;</td>
<td class=ms-cal-nodataBtm2 >&nbsp;</td>
<td class=ms-cal-nodataBtm2 >&nbsp;</td>
<td class=ms-cal-nodataBtm2 >&nbsp;</td>
<td class=ms-cal-nodataBtm2 >&nbsp;</td>
<td class=ms-cal-workitem2B >&nbsp;</td>
<td class=ms-cal-workitem2B >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-weekempty >&nbsp;</td>
<td class=ms-cal-weekempty >&nbsp;</td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f3\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f3\u002f2009','Day');" tabindex=9 >3</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f4\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f4\u002f2009','Day');" tabindex=10 >4</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f5\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f5\u002f2009','Day');" tabindex=11 >5</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f6\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f6\u002f2009','Day');" tabindex=12 >6</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f7\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f7\u002f2009','Day');" tabindex=13 >7</a></div></td>
<td class=ms-cal-topday-today onMouseOver="this.className = 'ms-cal-topday-todayover';" onMouseOut="this.className = 'ms-cal-topday-today';" onclick="MoveToViewDate('5\u002f8\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f8\u002f2009','Day');" tabindex=14 >8</a></div></td>
<td class=ms-cal-topday onMouseOver="this.className = 'ms-cal-topdayover';" onMouseOut="this.className = 'ms-cal-topday';" onclick="MoveToViewDate('5\u002f9\u002f2009','Day');" ><div><a href="javascript:MoveToViewDate('5\u002f9\u002f2009','Day');" tabindex=15 >9</a></div></td>
</TR>
<TR>
<td class=ms-cal-weekempty rowspan=6 >&nbsp;</td>
<th scope="row" class=ms-cal-week onMouseOver="this.className='ms-cal-weekselected';" onMouseOut="this.className='ms-cal-week';" rowspan=6 title="May 03 - May 09" onClick="javascript:MoveToViewDate('5\u002f3\u002f2009','Week');" ><div class=ms-cal-weekbox> <a href="javascript:MoveToViewDate('5\u002f3\u002f2009','Week');" tabindex=8 title="May 03 - May 09" ><img border=0 src='/_layouts/images/blank.gif' class='ms-cal-blankimage' alt='May 03 - May 09'></a></div></th>
</TR>
<TR>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem rowspan=3 ><table border=0 cellspacing=0 cellpadding=0 dir="">
<tr>
<td class="ms-cal-monthitem"><a onFocus="OnLink(this)"
href="/crmc/1200/Lists/Calendar/DispForm.aspx?ID=5.0.2009-05-04T18:30:00Z"
ONCLICK="GoToLink(this);return false;" target="_self"
tabindex=10
> <NOBR><b>14:30</b></NOBR><br>
• </a> </td>
</tr>
</table></TD>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem ><table border=0 cellspacing=0 cellpadding=0 dir="">
<tr>
<td class="ms-cal-monthitem"><a onFocus="OnLink(this)"
href="/crmc/1200/Lists/Calendar/DispForm.aspx?ID=7"
ONCLICK="GoToLink(this);return false;" target="_self"
tabindex=13
> <NOBR><b>12:00</b></NOBR><br>
• </a> </td>
</tr>
</table></TD>
<td class=ms-cal-todayitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem rowspan=2 ><table border=0 cellspacing=0 cellpadding=0 dir="">
<tr>
<td class="ms-cal-monthitem"><a onFocus="OnLink(this)"
href="/crmc/1200/Lists/Calendar/DispForm.aspx?ID=3"
ONCLICK="GoToLink(this);return false;" target="_self"
tabindex=13
> <NOBR><b>16:00</b></NOBR><br>
• </a> </td>
</tr>
</table></TD>
<td class=ms-cal-todayitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-todayitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
<td class=ms-cal-todayitem >&nbsp;</td>
<td class=ms-cal-workitem >&nbsp;</td>
</TR>
<TR>
<td class=ms-cal-workitem2B >&nbsp;</td>
<td class=ms-cal-workitem2B >&nbsp;</td>
<td class=ms-cal-workitem2B >&nbsp;</td>
<td class=ms-cal-workitem2B >&nbsp;</td>
<td class=ms-cal-workitem2B >&nbsp;</td>
<td class=ms-cal-todayitem2B >&nbsp;</td>
<td class=ms-cal-workitem2B >&nbsp;</td>
</TR>
</TABLE></td>
</tr>
</table>
</BODY>
</HTML>

ChuckLew
05-14-2009, 10:36 PM
I simplified the code a bit more so I'm calling less statements and not using any shorthand. I can see things more clearly now but I'm even more stunned. Here is my code now:


<script type="text/javascript">
function CalLinkForward(){
var aForward=document.getElementsByTagName('a');
for(var i=0;i<aForward.length;i++){
if (aForward[i].href.match(/javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/)) {
var scan = /javascript:MoveToViewDate\(\'([^\\]+)\\u002f([^\\]+)\\u002f([^']+)\',\'Day\'\);/;
var getDates = aForward[i].href;
var result = getDates.match(scan);
var returnedDate = result[1] +'/'+ result[2] +'/'+ result[3];
aForward[i].href = 'Lists\/Calendar\/calendar.aspx?CalendarDate=' + returnedDate + '&CalendarPeriod=Day'
aForward[i].parentNode.parentNode.onclick=function(){window.location='Lists\/Calendar\/calendar.aspx?CalendarDate=' + returnedDate + '&CalendarPeriod=Day';};
}
}
}
</script>

The href on the anchor tags are working the way I had expected, but the onclicks are still returning only the last value. I'm using the exact same variables to write them both. What is the difference between href and onclick? The variable "returnedDate" should equal "returnedDate" regardless, right? Well, obviously not. Can anyone help me understand my frustrations?

ChuckLew
05-18-2009, 02:17 PM
In the interest of moving forward with my project, I have decided to remove the onclick event on each of the TDs. Now the users can only click on the href (which functions they way I intended). Its not perfect, but at least it doesn't do anything I don't want (just not what I DO want). I'm still very interested in understanding the reason(s) for this peculiarity. If someone with an answer to these issues should happen across this thread, please leave a comment or point me towards some information. Randomuser773 and DrFish, thank you for the thought you gave my problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum