'Inteligenty' dom ze sterownikiem PLC

 Language:
Szukanie zaawansowane  

Aktualności:

Powrót do strony głównej: www.edom-plc.pl

Autor Wątek: HTML / Javascript / Edom JS  (Przeczytany 3886 razy)

Crp

  • Newbie
  • *
  • Wiadomości: 2
    • Zobacz profil
HTML / Javascript / Edom JS
« dnia: Września 14, 2015, 03:54:36 pm »

Hello,

I am trying to figure out the on how the JS library you wrote works but i have on problem with reading and storing a value in javascript. (i am a newbie)

i have the following code:

var PLCValue;

$('#Value').ReadValue({
address:  'MW0'
});

I am using the function .ReadValue to read the value from the MW0 adress. But how can i store the value from this function in variable PLCValue

if i try this and use alert to check the value it says 'undefined'

var PLCValue;

$(PLCValue).ReadValue({
address:  'MW0'
});

alert(PLCValue);
Zapisane

admin

  • Administrator
  • Sr. Member
  • *****
  • Wiadomości: 313
    • Zobacz profil
Odp: HTML / Javascript / Edom JS
« Odpowiedź #1 dnia: Września 17, 2015, 08:24:52 pm »

Hello,

Please check you what jQuery is and how it works.  The $(.....) is a jQuery selector. The way it is used here:

$('#Value').ReadValue({....  it shoud assign the value red from MW0 to the content of the #Value div.  To access it you should check out $('#Value').text() or $('#Value').html() so the content of the div.  In your code it could be like

var myValue = parseInt($('#Value').text()).

So to sum it up: do not confuse JS variables (var something) with DOM elements ($('#divID')).
Zapisane

Crp

  • Newbie
  • *
  • Wiadomości: 2
    • Zobacz profil
Odp: HTML / Javascript / Edom JS
« Odpowiedź #2 dnia: Września 21, 2015, 11:56:22 am »

Hello,

Please check you what jQuery is and how it works.  The $(.....) is a jQuery selector. The way it is used here:

$('#Value').ReadValue({....  it shoud assign the value red from MW0 to the content of the #Value div.  To access it you should check out $('#Value').text() or $('#Value').html() so the content of the div.  In your code it could be like

var myValue = parseInt($('#Value').text()).

So to sum it up: do not confuse JS variables (var something) with DOM elements ($('#divID')).

Thank you for your help. I tried your method: var myValue = parseInt($('#Value').text())
And after i use alert(myValue); to see what the outcome is. But i keep getting NaN (Not a Number). So i think this mehod is not working.
Zapisane