p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   HTML Code Clinic (http://p2p.wrox.com/forumdisplay.php?f=90)
-   -   Transferring a variable value (http://p2p.wrox.com/showthread.php?t=31521)

losmon July 15th, 2005 05:22 AM

Transferring a variable value
 
I'm currently attempting to show a scrolling marquee when the value of my variable doesn't read "NO CURRENT ADVISORIES". If other than that, it will scroll a message, allowing the user to click on the marquee and a new web page will be displayed.
My variable is in an xml file, and I'm using the "document.getElementById" statement. It is reading the xml just fine. I'm not sure of the code needed transferring "message" to my IF statement.
I'm not having any success doing it.:(
(The div id statement is being used as a test making sure I'm pulling the xml value correctly, and it is working.)

Code:

<html>
<head>
<script type="text/javascript">
var xmlDoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("http://www.jlocon.com/wdfulldata.xml");
getmessage()
}
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load("http://www.jlocon.com/wdfulldata.xml");
xmlDoc.onload=getmessage
}
else
{
alert('Your browser cannot handle this script');
}
}function getmessage()
{
document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("noaaw")[0].firstChild.nodeValue;
}
<!--
if (message != "NO CURRENT ADVISORIES")
      {
       document.write("<table border='1' cellpadding='0' cellspacing='0' width=550 bgcolor='RED'><tr><td><a

href='http://www.jlocon.com/laridx.htm'><marquee scrolldelay='125'

width='550'>NORTHERN ILLINOIS-CHICAGO AREA - WEATHER WARNING ISSUED ... [Click here for details]

</marquee></a></td></tr></table><br>");}
//-->
</script>
</head>
<body onload="loadXML()">
<div id="message" style="background-color:pink"></div>

</body>
</html>


Lar

joefawcett July 17th, 2005 05:31 AM

When you retrieve your content store it:
Code:

var sContent = xmlDoc.getElementsByTagName("noaaw")[0].firstChild.nodeValue;
then test it against "NO CURRENT ADVISORIES"
Code:

if (sContent == "NO CURRENT ADVISORIES")
{
  //display no advisory message
}
else
{
  //write marquee
}

--

Joe (Microsoft MVP - XML)

losmon July 17th, 2005 07:29 AM

Joe;
Thank you kindly for the update, I've made the change and it works ok as a standalone.
Now the next phase. Why when I put this into a regular html page, that it will register either condition and then open a brand new page? I thought it would just write it on the same page where the coding is located. Any suggestions there?

Lar

joefawcett July 19th, 2005 01:26 AM

You can only "document.write" to an open page, one that has not finished loading and rendering. To adjust content after loading there are many options but the most standard is to use the innerHTML property. For example if you have a div with an id of "divMessage" then to change this:
Code:

<div id="divMessage">Hello world</div>
to this:
Code:

<div id="divMessage">Hello Lar</div>
use this script:
Code:

var oMessageDiv = document.getElementById("divMessage");
oMessageDiv.innerHTML = "Hello Kar";

So you need to set up a div or a span to hold your marquee element.

As a side issue there's not much point worrying about cross browser compatibility with your code as "marquee" is IE only.

--

Joe (Microsoft MVP - XML)

losmon July 19th, 2005 04:03 AM

Joe,
Thanks again for your input. You're working with a newbie to JS and I'm not grasping where to put that type of a statement within my codeing. I understand what you're saying, but the coding is the question, any help there?

Lar


All times are GMT -4. The time now is 07:59 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.