473,324 Members | 2,257 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,324 software developers and data experts.

How to compare two Ajax elements

Ok so I'm trying to monitor and control something with a Pic-web from microchip. I managed to program it all except for one thing. I need to compare two temperatures that it gives me, and if one of them is smaller that the other then a relay need to be activated, if its bigger or equal then another relay must be activated. From what I understood Pic-web updates an xml file (status.xml) then the website (using ajax) takes the values from there and displays them on the web page.

This is the code in my xml file
Expand|Select|Wrap|Line Numbers
  1. <temp0>~temp~</temp0>
  2. <temp2>~tempc~</temp2>
This is the code for the temperatures
Expand|Select|Wrap|Line Numbers
  1.     document.getElementById('temp0').innerHTML = getXMLValue(xmlData, 'temp0');
  2.     document.getElementById('temp2').innerHTML = getXMLValue(xmlData, 'temp2');
And this is the code I use to display them in my web page
Expand|Select|Wrap|Line Numbers
  1. <span id="temp0"style="font-weight:normal">?</span>
  2. <span id="temp2"style="font-weight:normal">?</span>
I have almost 0 knoledge of ajax
I tried to compare them with

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. if(temp2==temp0) document.write("On".fontsize(4).fontcolor("green"));
  3. else document.write("Off".fontsize(4).fontcolor("red"));
  4. </script>
but it just displays OFF
Jun 19 '12 #1

✓ answered by Sorinpass

found the answer if anyone is interested

Expand|Select|Wrap|Line Numbers
  1.     var temp0 = parseFloat(document.getElementById('temp0').innerHTML)
  2.     var temp2 = parseFloat(document.getElementById('temp2').innerHTML)
  3.  
  4.     if( temp0 < temp2 ) {
  5.         document.getElementById('temp3').innerHTML = '<font color="#00FF00">ON</font>';
  6.     } else {
  7.         document.getElementById('temp3').innerHTML = '<font color="#FF0000">OFF</font>';
  8.     }
This will display ON if temp2 > temp0

and OFF if temp0 < temp2

2 2064
found the answer if anyone is interested

Expand|Select|Wrap|Line Numbers
  1.     var temp0 = parseFloat(document.getElementById('temp0').innerHTML)
  2.     var temp2 = parseFloat(document.getElementById('temp2').innerHTML)
  3.  
  4.     if( temp0 < temp2 ) {
  5.         document.getElementById('temp3').innerHTML = '<font color="#00FF00">ON</font>';
  6.     } else {
  7.         document.getElementById('temp3').innerHTML = '<font color="#FF0000">OFF</font>';
  8.     }
This will display ON if temp2 > temp0

and OFF if temp0 < temp2
Jun 19 '12 #2
acoder
16,027 Expert Mod 8TB
Try to avoid using <font> tags - they're deprecated. Try using CSS classes, e.g.
Expand|Select|Wrap|Line Numbers
  1. .on {
  2.     color: #00FF00;
  3. }
and in the HTML:
Expand|Select|Wrap|Line Numbers
  1. <span id="temp3" class="on">ON</span>
To set the class with javascript:
Expand|Select|Wrap|Line Numbers
  1. temp3.className = "on";
Jun 20 '12 #3

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

Similar topics

0
by: Ex-Em-El | last post by:
Hello !! I have this xml file : <?xml version="1.0" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="tables.xsl"?> <aaa xmlns="http://tempuri.org/My.xsd"> <Dog> <DogName>f1</DogName>...
21
by: vadymus | last post by:
Hello, I need to compare 2 id names but not their values. For example: document.getElementById(i) == document.getElementById(j) these elements above seem to give error or do not work. My...
3
by: Frank Rizzo | last post by:
I've had a windows service, that I've written and compiled with vs2003 and .net framework 1.1, running just fine on windows server 2003 for a long while. Recently the service was installed on...
1
by: wartech | last post by:
Hey everyone, My objective here is to be able to sort the array that i created from a structure. When I attempt to do this I get a message stating "Failed to compare two elements in the array". ...
8
by: BillE | last post by:
I have an existing asp.net 2.0 webforms app using master/content pages, and it works fine. I added some Ajax elements, including some UpdatePanels and modal PopUp panels which contain asp.net...
2
by: m.schaeffer | last post by:
Hello, my problem is, that if i create a new website with Visual Studio 2005 and I choose "AJAX enabled Website" everything works fine. But if I try to do the same with an existing Website...
3
sujathaeeshan
by: sujathaeeshan | last post by:
hi all, here is xml file..... <root> <Xmltype> <owner NAME="Legal Entity 1"></owner> <LegalEntity NAME="Legal Entity 1"></LegalEntity> <lob NAME="Line Of Business 1"></lob>...
4
by: beary | last post by:
Does anyone know if it's possible to take an array element in one array and compare it with every array element in another array, given that the spelling might not be exactly the same and there might...
5
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a Container that is an an Array List of Class Each ArrayList element can be the class or a another ArrayList of Class So there the ArrayList could look like Element 1 - Class...
0
by: xmlnovice | last post by:
Is there any way of requiring the value of an element's attribute to equal the value of a child element of the previous element. What I mean is hopefully explained by the following snippet from an...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.