Strange, not sure how it's working for you in console. 

In my Chrome console I get this when I manually try it:

tbl = $('.widget_contents', $('current_widget'));
91wind.js:2 Uncaught ReferenceError: $ is not defined
    at get_realtime (wind.js:2)
    at wind.js:27




On Tuesday, December 3, 2019 at 10:43:08 AM UTC-5, Jared wrote:
>
> Adding jQuery actually breaks the whole function haha.  I was trying to 
> avoid jQuery because I'm so close without it (plus it's just more stuff 
> I've never worked with).
>
> And again, the function works perfectly fine if I load it into the browser 
> myself after the page loads.  I don't think it's the function, I think it's 
> the timing of it being loaded.
>
> If you want to see what I mean, here is my page:  
> http://108.40.120.73:28926/weewx/index.html
>
> You can see the undefined error in the console, but if you re-load the 
> function into the console yourself after the page loads, you'll see it 
> works fine.  It updates Wind in the Current Conditions window.
>
> function get_realtime() {
>>   tbl = $('.widget_contents', $('current_widget'));
>>   r4 = tbl.getElementsByTagName("tr")[4];
>>   r4d1 = r4.getElementsByTagName("td")[1];
>>   var xhttp = new XMLHttpRequest();
>>   xhttp.onreadystatechange = function() {
>>     if (this.readyState == 4 && this.status == 200) {
>>       rt = this.responseText.split(" ")
>>       if (rt[6] && rt[13] && rt[11]) { 
>>         rt = this.responseText.split(" ")
>>         rtstr = rt[6].split(".")[0]+" "+rt[13]+" "+rt[11];
>>         if ((parseInt(rt[6], 10) < 10)) {
>>           r4d1.innerHTML = rtstr;
>>         } 
>>         else if ((parseInt(rt[6], 10) >= 20)) {
>>           r4d1.innerHTML = rtstr.fontcolor("red");
>>         }
>>         else {
>>           r4d1.innerHTML = rtstr.fontcolor("green");
>>         }
>>       }
>>     }
>>   };
>>   xhttp.open("GET", "realtime.txt", true);
>>   xhttp.send();
>> }
>>
>
>
>
> On Tuesday, December 3, 2019 at 10:25:50 AM UTC-5, Pat wrote:
>>
>> $ is a shortcut for the word jQuery. Make sure you have the jquery 
>> library loaded in the header, or just replace $ with the word jQuery
>>
>>
>> On Tuesday, December 3, 2019 at 10:04:09 AM UTC-5, Jared wrote:
>>>
>>> Hi,
>>>
>>> I made a little JavaScript function (wind.js) that will update the 
>>> Seasons *current_widget* table with wind values from CRT realtime.txt.  
>>> The function works perfectly fine if I drop it into the browser console 
>>> after the page loads, but for the life of me I cannot get this thing loaded 
>>> by itself.  The console always shows the error *$ is not defined* in 
>>> wind.js.  The errant line is *tbl = $('.widget_contents', 
>>> $('current_widget'));* where I am grabbing the table object.
>>>
>>> The index.html.tmpl <body> sections runs the setup(); function "onload" 
>>> from the seasons.js file, which looks like it establishes the widgets.  If 
>>> I drop <script src="wind.js"></script> after </body>, why are the widget 
>>> objects still undefined?  I've tried various methods of deferring this 
>>> script from being run, but nothing is working.
>>>
>>> This is literally the first thing I've ever created in JavaScript and am 
>>> a complete newbie in working with web programming, so go easy on me :)
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/1c13e153-cdd3-4343-a85c-79d526ca8ce9%40googlegroups.com.

Reply via email to