Jump to content

Using Javascript To Change Javascript?


chibineku
 Share

Recommended Posts

EDIT: I've figured it out, so don't reply to this! Please delete, mods... :EDITI want to use this script:

<script type="text/javascript"> var xmlDoc;if (window.ActiveXObject){// code for IExmlDoc=new ActiveXObject("Microsoft.XMLDOM");}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.xmlDoc=document.implementation.createDocument("","",null);}else{alert('Your browser cannot handle this script');}var x=xmlDoc.getElementsByTagName("CONTENT");function news(){ xmlDoc.async=false;xmlDoc.load("news.xml");news=(xmlDoc.getElementsByTagName("CONTENT")[0].childNodes[0].nodeValue);document.getElementById("content").innerHTML="<p class='wrap'>"+news+"</p>"}</script>
a number of times on my site, called by onclicks from a menudiv:
<p class ="table" onclick="news()">news</p>
Is there any way to alter the script from within the menudiv so that I don't need to copy the script out 15 times? It's pretty messy with that many scripts, and they're practically the same. I don't know if I can use an external script that will alter the relevant parts as required (i.e. the variable news becomes film if you click the film 'link'.Any thoughts?
Link to comment
Share on other sites

EDIT: I've figured it out, so don't reply to this! Please delete, mods... :EDITI want to use this script:a number of times on my site, called by onclicks from a menudiv:Is there any way to alter the script from within the menudiv so that I don't need to copy the script out 15 times? It's pretty messy with that many scripts, and they're practically the same. I don't know if I can use an external script that will alter the relevant parts as required (i.e. the variable news becomes film if you click the film 'link'.Any thoughts?
Hm. When I say I've figured it out, I really haven't. I can't seem to get a script to work that reads the menu items and then assigns the name of the menu item to a variable and loads the relevant xml file when the menu item is clicked on.
Link to comment
Share on other sites

If all your XML documents had the same structure, you could use a parameter in your function:

function changeSection(content) {  xmlDoc.async=false;  xmlDoc.load(content + ".xml")  result = xmlDoc.getElementsByTagName("CONTENT")[0].childNodes[0].nodeValue;  document.getElementById("content").innerHTML = "<p class='wrap'>" + result + "</p>";}

And then call the function with a parameter:

<p class ="table" onclick="changeSection('news')">news</p>

Link to comment
Share on other sites

If all your XML documents had the same structure, you could use a parameter in your function:
function changeSection(content) {  xmlDoc.async=false;  xmlDoc.load(content + ".xml")  result = xmlDoc.getElementsByTagName("CONTENT")[0].childNodes[0].nodeValue;  document.getElementById("content").innerHTML = "<p class='wrap'>" + result + "</p>";}

And then call the function with a parameter:

<p class ="table" onclick="changeSection('news')">news</p>

You are a beautiful individual, do you know that?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...