Author Topic: Script questions?  (Read 2958 times)

0 Members and 1 Guest are viewing this topic.

Offline aadamson

  • Member
  • *
  • Posts: 14
    • N1IP's Live Weather
Script questions?
« on: October 29, 2007, 09:21:34 AM »
Not sure if this is the appropriate place to post script questions, but if not, move it and I'll note appropriately.

Ok, so I have the AJAX stuff up and running.  However it works a little different than I expected.  I wanted to graft it into an existing format that I've had, it's a table format with both a textual version of the weather and the specific numbers.  This is where I found the gotcha.

I wanted to use the temp, for example, in 2 places.  However, when I tried to put the span in with the ajaxtemp variable, I found that I couldn't use it more than once.  The first time it printed the tempurature as is should have, but the second time it printed nothing.  It appears that if you want to have multiple references to the same variable, that you have to modify the .js code to add another core variable.  In my case, to prove the above, I added an ajaxtemp1 and then inserted the span code with the updated id and poof, it all worked.

But, the above seems overkill and a PITA just to have the same variable referenced at multiple places in the same web format.  So, is there a better/easier way to accomplish what I want to do?

Thanks and let me know,
Alan
« Last Edit: October 29, 2007, 10:13:00 AM by aadamson »

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6883
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Script questions?
« Reply #1 on: October 29, 2007, 11:13:03 AM »
Alan,
You've discovered how to do it.. add a new ajax... variable to the script.
It's an HTML requirement that the id= attributes be uniquely named on each HTML page (only one occurrence of a specific ID can appear on a page).

So if you want the temperature to appear twice on a page, just clone the code for 'ajaxtemp' and call it 'ajaxtemp2', then use the 'ajaxtemp2' markup for the second instance on your page.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline aadamson

  • Member
  • *
  • Posts: 14
    • N1IP's Live Weather
Re: Script questions?
« Reply #2 on: October 29, 2007, 11:30:31 AM »
Ken, as usual, thanks for the response... I might have to think thru this some, wonder if there is a way to streamline the updating thru the use of some arrays or other construct.... hmmm.  Hey, this ajax stuff is pretty cool btw....

So now to my next question.

In the PHP code, it looks like you echo the variable after it's passed thru a strip_units function.  So let me make sure I have this right.... That only works for the first time that the value is printed, the time it gets it from the tags...php file.  The rest of the time it just takes and stuffs the new value into the ID and that strip_units function isn't re-called correct?

The reason I ask is that try as I might to put a "space" between the number and the degree symbol, I couldn't figure out how to do it.  And it appears that I I really want that, that I'd also have to modify the .js file to support that formatting?

Alan

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6883
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Script questions?
« Reply #3 on: October 29, 2007, 02:19:31 PM »
I use the strip_units() php function to remove any trailing units on the variables from testtags.php that might contain units.  My WD setup has units included so I can feed the sample carterlake/AJAX pages, but my main PHP pages have units in the display.

The calls to strip_units() only effect the PHP variables -- the AJAX script variables are all 'plain' (just numbers) since that's how they appear in clientraw.txt.  The ajaxWDwx.js script optionally adds the UOM for the variable (depending on the showUnits JavaScript variable) for the display inside the associated id= ajax <span> tag pair.

If you want to add a space between the variable and the UOM, then you'll need to do that in both the sample PHP code AND the ajaxWDwx.js script like you say :-)

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Re: Script questions?
« Reply #4 on: October 30, 2007, 06:44:08 PM »
Alan,
You've discovered how to do it.. add a new ajax... variable to the script.
It's an HTML requirement that the id= attributes be uniquely named on each HTML page (only one occurrence of a specific ID can appear on a page).

So if you want the temperature to appear twice on a page, just clone the code for 'ajaxtemp' and call it 'ajaxtemp2', then use the 'ajaxtemp2' markup for the second instance on your page.

Best regards,
Ken

Yep, that's what I did on mine. I went into the appropriate ajax code, copied the part I wanted to clone, pasted it into the code, and gave it a new name. Then make the associated changes in your html code.  In my case I have today's high and low temps appearing twice on the same page, but doing the above automatically updates both occurrences whenever the high or low temps change.

Regards,

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3

 

anything