Jump to content

Recommended Posts

Posted

Hi,

 

 

Heres some basic code, what I'm trying to do is pull some text from a function in the head section but you can see it seems to be showing up before its called. Not sure If I have my terminology right. Am I doing something wrong? Heres the example of what it does in a browser http://www.kaulaiscool.com/random/js_problem.htm

><html>
<head>
<title></title>
	<script type="text/javascript">
		<!--

			function why()
				{
					document.writeln("sample text");
				}

		// -->
	</script>
</head>
<body>
<script type="text/javascript">
	<!--
		document.write("Here is some" + why() );
	// -->
</script>
<noscript>
	Your Browser does not support JavaScript.
</noscript
</body>
</html>

 

Thanks!

Posted

I just removed the why() and added it outside of the document.write in the body and it works fine, Is that the only way to do it?

 

 

Thanks

Posted

Your treating why() as if it IS a string. But why() actually PRINTS a string. What you had essentially put a writeln inside a write. Modify your why() function to say this, instead of the writeln():

 

function why()

{

return "sample text";

}

 

 

That should do the trick.

Posted

As a side note, I believe it's more correct to say:

 

<script language="javascript">

 

than it is to say:

 

<script type="text/javascript">

Posted

Thanks for the responses, I got it all working properly now. Normally I use xhtml, I just whipped that up real quick as an example, forgot that the two where different.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...