Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Search & Replace an onclick Event

    OK, here is a sample of the code I'm trying to look at and then change:

    Code:
    <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:

    Code:
    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:

    Code:
    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.

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    An event handler isn't a string, try

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

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

  • #3
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Randomuser773, thanks for the quick response. I think I must be missing something fundamental. This is how I interpreted your suggestion:

    Code:
    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?

  • #4
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by ChuckLew View Post
    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.

  • Users who have thanked randomuser773 for this post:

    ChuckLew (05-18-2009)

  • #5
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #6
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I'm still trying to figure this one out. If anyone can help me understand what I missing here, it would be appreciated.

  • #7
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <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?

  • #8
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

    Code:
    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:

    Code:
    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.

  • Users who have thanked DrFish for this post:

    ChuckLew (05-18-2009)

  • #9
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    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

  • #10
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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.
    Last edited by ChuckLew; 05-13-2009 at 05:44 PM. Reason: typo

  • #11
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    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
    Code:
    var getonclick = tdForward[i].getAttribute('onclick').toString();
    Sorry don't have the time to check if it works.

  • #12
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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."

  • #13
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <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:

    Code:
    <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>

  • #14
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <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?

  • #15
    New Coder
    Join Date
    May 2009
    Location
    Virginia Beach, Virginia
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •