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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menus

Status
Not open for further replies.

Phonez

Technical User
Jan 16, 2002
58
GB
Hi,

Is there any way to dynamically change the text on a page in javascript without refreshing the page.

I am trying to make a hierarchical menu in javascript but after writing the contents of a function to the page you cannot run other functions unless you refresh the page first.

Thanks in advance

Jon [afro]
 
Do you mean that once a user selects a option from the nenu they cannot choose another option?? Do you have the script posted online so we can take a look at it?? I have not failed; I merely found 100,000 different ways of not succeding...
 
I am wanting to do it is so when you click on a link, a new menu is written to the page

here is the code I have got, you can do it once but then it errors

Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
document.write(&quot;home&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:refabout();>about plus</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:refproducts();>products</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:education();>education</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:clients();>clients</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:news();>news room</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:contact();>contacting</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:careers();>careers</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:seminars();>seminars</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:links();>links</a>&quot;);


function about(){
document.write (&quot;About&quot;);
}

function products(){
document.write(&quot;home&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:refabout();>about</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:refproducts();>products</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;aos&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:education();>education</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:clients();>clients</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:news();>news room</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:contact();>contacting</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:careers();>careers</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:seminars();>seminars</a>&quot;);
document.write(&quot;<br>&quot;);
document.write(&quot;<a href=javascript:links();>links</a>&quot;);
}

function education(){
document.write (&quot;education&quot;);
}

function clients(){
document.write (&quot;clients&quot;);
}

function news(){
document.write (&quot;news&quot;);
}

function contact(){
document.write (&quot;contact&quot;);
}

function careers(){
document.write (&quot;careers&quot;);
}

function seminars(){
document.write (&quot;seminars&quot;);
}

function links(){
document.write (&quot;links&quot;);
}
//-->
</SCRIPT>
 
The document.write method is only useful as the page is parsed by the browser. After the page has loaded any call to document.write will generally rewrite the entire document. To dynamically change elements of a html page after parsing without refreshing the browser you will need to access the document object model.

The simplest way to do this is to create a div and change the innerHTML property of it something like
Code:
<script>
function changeDivContents(){
//check browser supports DOM IE5+ & NS6
if(document.getElementById){
document.getElementById(&quot;mydivId&quot;).innerHTML = &quot;new html&quot;;
}
//check if IE4
else if(document.all){
document.all.[&quot;mydivid&quot;].innerHTML = &quot;new html&quot;;
}
//check if NS4
else if(document.layers){
var divtext = &quot;new html&quot;;
document.layers[&quot;mydivid&quot;].document.open();
document.layers[&quot;mydivid&quot;].document.write(divtext);
document.layers[&quot;mydivid&quot;].document.close();
}
}
</script>
hope this helps

rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top