Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A convoluted src within a src

Status
Not open for further replies.

mikemedia

Programmer
Apr 28, 2006
39
US
I'm writing a dynamic menu using an external js file.
The js function begins the script. I've then used "document.write" to display the html tags.

However, I cannot make an event coded within a html <div> tag exectute the js function.

document.write(<'dt class="style1" onclick="javascript:expand('smenu2');">RECRUITS & FAMILY</dt>');

I've considered getElementByID

Any other ideas?
 
If that example is copied and pasted, you need to switch your opening single quote and opening tag bracket so the bracket is INSIDE the quote.

If the example isn't copied and pasted, you need to do that so we don't end up chasing the wrong errors.

Show fake code, get fake answers. Show real code, get real answers.

Lee
 
document.write is, for the most part, COMPLETELY unusable after the page has loaded. If document.write is used during page load it can assist with the generation of the initial page. If it is used dynamically (after the page has loaded) then it will completely overwrite the contents of the page.

I suggest using innerHTML or DOM methods to change the content of the page after it has completed loading.

-kaht

[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
[banghead]
 
trollacious:

That was the exact line.

I almost got your idea, but I'm a visual kinda' guy. Do you mind replicating your explanation?
 
Oh, I see what you meant now. That was a typo.
This is the ACTUAL line.

It still doesn't work.

kaht, help me out with innerHTML?

document.write('<dt class="style1" onclick="javascript:expand('smenu2');">RECRUITS & FAMILY</dt>');
 
This is the easy way.
Code:
<script type="text/javascript">
<!--//
var span = document.getElementById("test");
var html = "<dt class=\"style1\" onClick=\"expand('smenu2')\">RECRUITS & FAMILY</dt>";
span.innerHTML = html;
//-->
</script>

<span id="test"></span>

M. Brooks
 
mbrooks beat me to it :)

-kaht

[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top