WEB Why isnt my javascript stuff working ? :wtc:

Discussion in 'OT Technology' started by Ricky, Jun 14, 2008.

  1. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    Code:
    <html>
    <head>
    <script type="text/javascript">
    	Replace_Text = "Replace Me"
    
    	a = document.getElementsByTagName("TH")
    	for (i=0; i<a.length; i++)
    	if((a[i].className=="titlemedium")&&(a[i].innerHTML.match("Ricky"))){
    	a[i].innerHTML=a[i].innerHTML.replace("Ricky",Replace_Text);
    	}
    </script>
    </head>
    <body>
    	<th align="left" width="59%" class='titlemedium'>Ricky</th>
    </body>
    </html>
     
  2. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    I'm a js noob, but it looks to me like the script just isn't being called.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function Ricky() {
    	Replace_Text = "Replace Me"
    
    	a = document.getElementsByTagName("TH")
    	for (i=0; i<a.length; i++)
    	if((a[i].className=="titlemedium")&&(a[i].innerHTML.match("Ricky"))){
    	a[i].innerHTML=a[i].innerHTML.replace("Ricky",Replace_Text);
    	}
    }
    </script>
    </head>
    <body onload="Ricky()"><table>
    	<th align="left" width="59%" class='titlemedium'>Ricky</th>
    </table></body>
    </html>
    
     
  3. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    thanks that looks like it fixed it :o

    Do you know how to make it so i can replace multiple words to just a single word.

    Like i want it to replace joe,mike,bob and kyle to Ricky.

    Possible ? :o
     
  4. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    if you know what the names are, the string replace function can take regular expressions, so you could do all the searches on one line.. or you could do multiple searches, etc
     
  5. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    So what i can do something like this ?
    Code:
    	a[i].innerHTML=a[i].innerHTML.replace("joe",Replace_Text);
    	a[i].innerHTML=a[i].innerHTML.replace("mike",Replace_Text);
    	a[i].innerHTML=a[i].innerHTML.replace("dave",Replace_Text);

    So im guessing im going to have to use the match() function for each one i replace too right ?

    theres no way to just do something like this ?

    Code:
    a[i].innerHTML=a[i].innerHTML.replace("dave";"mike";"joe",Replace_Text);
     
  6. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    you don't need the match function at all.. it's redundant.

    the replace function can search for a regular expression, so you can use that to search for multiple names on one line
     
  7. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    thanks. that helps out a lot
     
  8. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    			function Ricky() {
    				var a = document.getElementsByTagName("TH");
    				for (i = 0; i < a.length; i++) {
    					if (a[i].className == "titlemedium") {
    						a[i].innerHTML = a[i].innerHTML.replace(/Bobby|Nancy/, "Ricky");
    					}
    				}
    			}
    		</script>
    	</head>
    	<body onload="Ricky()">
    		<table>
    			<th align="left" width="59%" class='titlemedium'>Bobby</th>
    			<th align="left" width="59%" class='titlemedium'>Nancy</th>
    		</table>
    	</body>
    </html>
    
     
  9. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
  10. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    thanks once again. that even helped out more :bowdown:
     
  11. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    You dont have OT access ?

    PM me your paypal and i'll cover the charges
     
  12. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    don't worry about it. I waste WAY too much time in the main forum
     

Share This Page