Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
| Search | Today's Posts | Mark Forums Read
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2005, 05:22 AM
Registered User
 
Join Date: Jul 2005
Location: Elgin, IL, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old July 17th, 2005, 05:31 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old July 17th, 2005, 07:29 AM
Registered User
 
Join Date: Jul 2005
Location: Elgin, IL, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old July 19th, 2005, 01:26 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old July 19th, 2005, 04:03 AM
Registered User
 
Join Date: Jul 2005
Location: Elgin, IL, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Transferring files sachtaridis Visual C++ 0 November 22nd, 2007 07:31 AM
transferring/copying from spreadsheet to another Aprile Excel VBA 2 September 7th, 2007 06:16 AM
Transferring Dlls from one server to another Pallavs20 General .NET 0 October 13th, 2005 02:13 AM
Transferring data between functions Fightfish C# 2 July 6th, 2005 12:21 PM
Transferring Import Specifications timmaher Access 4 September 1st, 2003 10:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.