473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help with writting a javascript that displays my current weather conditions

I want to add the current weather conditions in my area to my site. I've looked at some of the sites that will give you a generated script to add to your site but I don't like the way they look. I want to create my own using DIVs to house the info and javascripts to get the info and place it in those DIVs.

I've already created the DIVs and now need a javascript to fetch/place the current conditions from my area. I have a DIV for hi/location/lo, Current Temp, image. I'm real new to javascripting and have no idea of were to start. I like how th dashboard weather widget works and took a look at the javascript file to see how that was done but got lost.

Could anyone help? How to start?

Any help would be great.

Thanks
Apr 24 '07 #1
2 2540
r035198x
13,262 8TB
I want to add the current weather conditions in my area to my site. I've looked at some of the sites that will give you a generated script to add to your site but I don't like the way they look. I want to create my own using DIVs to house the info and javascripts to get the info and place it in those DIVs.

I've already created the DIVs and now need a javascript to fetch/place the current conditions from my area. I have a DIV for hi/location/lo, Current Temp, image. I'm real new to javascripting and have no idea of were to start. I like how th dashboard weather widget works and took a look at the javascript file to see how that was done but got lost.

Could anyone help? How to start?

Any help would be great.

Thanks
Where are you getting the weather conditions from? How do you want to display them?
Apr 24 '07 #2
The national weather service offers current conditions in either XML or RSS. Here's the link.

http://www.weather.gov/data/current_obs/

I use the php curl() function to write the XML file to my web server and then parse it with javascript.

Try something like this:

function get_weather() {


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "XML URL");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$xml_content = curl_exec($ch);
$fp = fopen("weather.xml", "w+");
fwrite($fp, $xml_content);
fclose($fp);

curl_close($ch);
}


Call this function in your script and it will write the XML doc to weather.xml in the root folder of your web server.

I've found that you must save it to your web server first, as javascript doesn't work well with files from a 3rd party as a security meassure. Make a recursive setTimeout() function to call it up again about once an hour to get updates.
Apr 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Karin Jensen | last post by:
Hi - I am trying to use Javascript to put material inside a table (i.e. alongside the previous material) if the user's screensize is big enough and outide the table (beneath table) if it isn't. ...
4
by: none | last post by:
Below is an old count-up script that displays ok in MSIE with a bit of experimenting, but NS shows negative values that make no sense. Anyone know how to make it work ok in both? === Cut ===...
4
by: Paul M | last post by:
Larry, i've got an xml file which has multiple cities as the top level item. When i read it in using XMLReader, and define the variables, as below, it finds the correct number of cities in the...
20
by: none | last post by:
I have managed to get the below script *almost* working. However, it still has a problem calculating the number of months. The date I am trying to calculate from is Oct 15, 1994. With the correct...
5
by: Brie_Manakul | last post by:
Is there a way in javascript to do an if else that shows a script in an iframe? Let me know if that doesn't make sense. We have a portal and in a portlet I need to grab these javascript links to...
4
by: Brie_Manakul | last post by:
I need to set up an if else to show different weather scripts based on the city selection they choose. Any help on this would be great. Thanks! <%@ page language="java" import="java.util.*,...
27
by: SamJs | last post by:
WITH (this) { a = 5 } I'm finding that this.a = 5 will come from this expression. I would have thought that the search for a would come up undefined and leave it at that. Is JavaScript...
15
by: lucky | last post by:
Hi Guys You are probably my last chance to avoid getting crazy To help you understand my problem I have put images online showing the issue I have: http://www.australix.net/images/pb I...
4
by: shaynenash | last post by:
I wrote this script to calculate if water restrictions were in place if it was hotter than 25deg C. It has turned out to be a pretty good weather widget that can be used elsewhere. This was initially...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.