Page 3 of 3

Re: HTML Indicator Code

Posted: Mon Feb 07, 2011 6:17 pm
by nemiro
OK, bringing this back from the dead. I have most of my AJAX issues worked out. A very big thanks to Tod for pointing me in the right direction! It turns out that the problem had something to do with how the browser in an Android tablet was interacting with the NB. I am still not sure what the root cause of the problem was, but I found that by either clearing out the cache in the Android tablet periodically, or better, using a refresh in the HTML, so that the page itself would reload every now and again:

Code: Select all

<meta http-equiv="refresh" content="100;url=http://192.168.1.22/index.htm"/>
This kept the Android device from 'locking up', and which in turn would keep the NB from crashing. Again, I do not know what the issue really was, just that this single line of code seemed to fix it all.


OK, so I got my application working, and I can use Tod's AJAX example to pass strings back to the browser. Now that I have the working reliably, I would like to go that next step which will change a cell in a table colors. In this case, I would like to setup a simple ON / OFF indicator. So, if I were to hypothetically setup a two cell table, with ON in one cell and OFF in the other, I can see both the HTML and the CSS methods for changing the font color and the background, but the question is, how do I write the Javascript that will read the resulting string, and then select the right style to use? Do I use IF/THEN/ELSE, or do I use the JS version of a SWITCH statement (or something else entirely)? Once the "decision" has been made inside the JS, how does that make it back out into the HTML to do the actual style change? Can you assign an HTML element a variable name so that inside the JS, you can setup something like:

If (ajax_string == "ON"){
HTML_element = CSS_ON_Style;
}

Else {
HTML_element = CSS_OFF_Style;
}


Then back in the HTML would you have something like:

Code: Select all

<td height="75" class="HTML_element"><h2><strong><a href="index.htm?91">ON</a></strong></h2></td>



Sorry to sound like quite the novice, but I really am when it comes to this stuff. I appreciate everyone's help with this whole thing!

Re: HTML Indicator Code

Posted: Tue Feb 08, 2011 11:49 am
by tod
Every Html element can have an "id", javascript has a GetElementById call that will give you the node for that id. Then you can set the the background color by manipulating the style property of the node or by assigning a css style to the node.

YOUR_ELEMENT_ID = "theIdYouGaveToYourElement";
the_node = document.GetElementById(YOUR_ELEMENT_ID );
the_node.style.backgroundColor = "white";

There are lots of detailed JavaScript tutorials out there for free, and I've always liked David Flanagan's - JavaScript Definitive Guide series, published by O'Reilly for a thorough explanation.

Re: HTML Indicator Code

Posted: Tue Feb 08, 2011 12:49 pm
by nemiro
Tod-
Thanks for the recommendation, I just ordered the book.