Hey guys,

I've done this so many times before but I can't seem to get it working!! All I'm trying to do is in the JavaScript at the top change a span tag to whatever the current window location is but it doesn't work!

<div id='Box' class="whitebox">
	<div class="position">
	
	    <div name='domainBlock' id="textBlock">
  
	   <h1 align="center">Your Domain</h1> <br />
	     <span name="siteDomainName" id="domainNameText"></span> 
	</div>

I've tried EVERYTHING to change the value and I do not know why it will not change. The Span Tag is nested within two divs so I am not sure if that matters and I do not have a form element so I am not sure if that is relevant.

I've tried:

var myForm = document.getElementById("domainNameText");
 myForm.innerHtml = window.location;

//and

var myForm = document.getElementByName('siteDomainName');

But it causes a script error. Do I need to go down to the child elements to change this? any advice?

I think you are missing 's' getElementsByName

click here for more details

<html>
<head>
<script type="text/javascript">
function getElements()
  {
  var x=document.getElementsByName("x");
  alert(x.length);
  }
</script>
</head>
<body>

<input name="x" type="text" size="20" /><br />
<input name="x" type="text" size="20" /><br />
<input name="x" type="text" size="20" /><br /><br />
<input type="button" onclick="getElements()" value="How many elements named 'x'?" />

</body>
</html>

Line 1 and 2 in your code is what is needed to change the content on span. BUT you need to put this code after your span tag in the html.

HTML is render from top to bottom and so is the embedded javascript. If you put your javascript code at the top and try to get element which is not yet rendered will not work. So the best practice is put javascript code at the end of the page.

Hope this is what you were looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.