Forum Moderators: open
I just learned that I have a tool that gives me one of these possible values:
BL DUST
CLEAR
CLOUDY
DNS FOG
DRIZZLE
FOG
FOGGY
FRZ.RAIN
HAZE
H/DRIZZLE
H/RAIN
ICE
L/FOG
LGT.RAIN
L/RAIN
LSNO/FOG
M/CLEAR
M/CLOUDY
MIST
M/SUNNY
OVERCAST
P/CLOUDY
P/SUNNY
RAIN
SNOW
SUNNY
T-STORM
Depending on the weather, the value may be any one of these things, but these are the known possibilities. I don't have any control over which one is shown and when.
If I have this set to appear in <div class="[any of the items]">, is it possible to strip out the non-alphabetic characters and maybe convert the case?
For example, P/CLOUDY would become pcloudy, DNS FOG would become dnsfog, and LGT.RAIN would become lgtrain?
so we are finding any character that is NOT a-z or A-Z and replacing it with "".
var x = "VAL /UE";
x.replace(/[^a-z]/ig,"");
x.toLowerCase();
Thats all you need!
- JS
Oops, forgot to hit send on that followup. So am I looking at something like this?function weatherFilter() {
var x = "VAL /UE";
x.replace(/[^a-z]/ig,"");
x.toLowerCase();document.getElementById("weatherbox").class = "x");
}
Can I set the class this way with?
More like:
function weatherFilter(weatherType) {
weatherType.replace(/[^a-z]/ig,"");
weatherType.toLowerCase();
document.getElementById("weatherbox").className = weatherType;
}
then call it like this:
weatherFilter("LSNO/FOG");
this will set the className to: lsnofog
What's your address so I can send my bill ;)
- JS
The value is coming from a server-side process, but I have very little control over what I get from it. It's not PHP or ASP, but a proprietary system driving the whole site.
This whole thing is sort of my way of changing things from the inside, one little step at a time.
I may have hit a problem. The values that I get have line breaks on either side of them, resulting in this...weatherFilter("
OVERCAST
");Is this whitespace going to affect the script?
"unterminated string literal" - in firefox
is what your going to get. In this case, you need to remove \r & \n from the server output. If you CAN'T remove the \r\n, then you need to insert a " before the text and after the text, because this is vaild:
weatherFilter(
"OVERCAST"
);
Whatever the server side language, I would expect it to have some sort of trim() function or something...
- JS
but that seems like overkill....
- JS
Find the image 01.gif - 40.gif, strip the extension, then set the leftover value 01 - 40 as the class of the #weatherbox div.
I think the document.images[] collection is a starting point...
Trying to help in a different way... :)
Set the desired weather code into a hidden form field.
<input type="hidden" name="weatherCode" id="weatherCode" value="
M/SUNNY
">
function weatherFilter() {
var weatherType document.getElementById("weatherCode").value;
weatherType = weatherType.replace(/[^a-z]/ig,"");
weatherType = weatherType.toLowerCase();
document.getElementById("weatherbox").className = weatherType;
}
BTW, the function I posted earlier was wrong (i forgot the weatherType = before the replace and lowercase methods....
Not sure what your talking about with the document.images array...
- JS
The "=" was missing, but it's all good, because I think we have a winner!
Now, I just wish it would stop telling me that it's Mostly Sunny so I could do some more testing. I'll keep you posted, but I think this is it.
I really can't thank you enough for your help and your patience.