split error

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

split error

Post by moiseszaragoza »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok now i have some code 

to show you 

[syntax="javascript"]

function initializeClicks()
{
	if (document.links)
	{
	window.alert(document.links);
		var oldClick = (document.links[0].onclick) ? document.links[0].onclick : function() {};

		// this almost works as I would expect.
		// the original onclick handler for link[0] returns false, so it can suppress
		// the following of the href (it was originally designed to popup a new window
		// using javascript
		document.links[0].onclick = function() { doClick(); oldClick(); }
		document.links[0].onmousedown=alertBut;
		for (var i = 1; i < document.links.length; i++)
		{
			// problem here is that oldClickLoop remains in scope for the life of the page
			// and so each time I am assigning what I expect to be a temporary variable that only
			// exists through each iteration of the for loop, I am actually resetting this
			// variable and therefore, changing the onclick handlers of the previous links
			// I may have changed earlier in the loop.
			var oldClickLoop = (document.links[i].onclick) ? document.links[i].onclick : function() {};
			//alert(document.links[i]);
			//strlink = document.links[i];
			//document.links[i].onclick = function() { oldClickLoop(); }
			document.links[i].onmousedown=alertBut;
		}
	}
}


My error is in this block

Code: Select all

function alertBut( e, evElement ) {
//alert(evElement);
//Internet Explorer
  if( !e ) {
    if( window.event ) {
      //Internet Explorer
      e = window.event;
    } else {
      //total failure, we have no way of referencing the event
      return;
    }
  }
//Netscape compatible
  if( typeof( e.which ) == 'number' ) {

    e = e.which;
  } else if( typeof( e.button ) == 'number' ) {
    //DOM
    e = e.button;
  } else {
    //total failure, we have no way of obtaining the button
    return;
  }
  if( !evElement ) 
  { evElement = this; }
  /* 'this' will exist if I have used object.onEventName = alertBut;
  If I have passed evElement from the onmouseup attribute,
  'this' will refer to window */
  //window.alert( evElement + ' was clicked with button ' + e );
   URLAdress_e = evElement    
 window.alert(URLAdress);
 

  // My ERROR IS HERE 
    URL_Split= URLAdress_e.split('/'); // separeates te web address were ever if finds a "/" 
	
     
	 
   	window.alert(URL_Split[2]); // displays the 3ed positon of the split  (expectes a [url]http://www.name.com[/url]
   								// URL_Split[0] = http:
  								// URL_Split[1] = 
								// URL_Split[2] = domain name.com
 window.alert("XXX");
		 // Test for sites 
		 switch(URLAdress)
		{
			case google:
			  window.alert("you are in google");
			  break    
			case 'yahoo':
			 window.alert("you are going to yahoo");
			  break
			default:
			  window.alert("you are going to " + URLAdress_e);
		}


  // window.alert(URLAdress);
  //location.href='test4.asp';
  //return true;
}
</script>




Code: Select all


<body>
<ul>
	<li><a href="test3.asp">Internal </a></li>
	<li><a href="http://www.yahoo.com">Yahoo</a></li>
	<li><a href="http://www.google.com">google</a></li>
	<li><a href="http://www.moiseszaragoza.com">Moises Zaragoza</a></li>
	<li><a href="#">page link</a></li>
	<br>
onload="initializeClicks()"
</ul>
</body>

ok what's hapening is that my scropt is dieing when i go to split the URL

Code: Select all

// My ERROR IS HERE 
    URL_Split= URLAdress_e.split('/'); // separeates te web address were ever if finds a "/" 
any ideas how to fix that
thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Post by moiseszaragoza »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok I have been working on this and i think i have a better defenition of the error

I am trying to do a split inside a function but i am just not able 

[syntax="javascript"]

///////// This is  javaScript
function splitFunction(evElement) {

 // ruruerns  I am calling thins from a function htpp://www.name.com/xxx/xxx.asp
 window.alert("I am calling thins from a function " + evElement); 
 // line with error "OBJECT DOES NOT SUPRT PROPERTY OR METHOD
 split_evElement=evElement.split('/') // supose to separate when ever it finds a "/" 
 window.alert(split_evElement[2]);// show positn #3 name.com
 
return
}

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply