0
<script>
var source = new EventSource("panic.php");
source.onmessage=function(event) {
    document.getElementById("panic_status").innerHTML=event.data;
};
</script>

how do i set the element panic status into are variable in another script for example

var name = document.getElementById("panic_status").value;
Sterling Archer
  • 22,070
  • 18
  • 81
  • 118
  • `var name = document.getElementById("panic_status").innerHTML;` ...? – CBroe Mar 24 '18 at 21:58
  • if i use

    panic_status

    if will show up the value coming from the panic_status bur i need to set up this in another script as variable so that i can manipulated the value
    – RUHAIZAN FAZREEN ASHRAFF MOHD Mar 24 '18 at 22:18
  • First of all, that's invalid HTML, you can not next a div into h1. Secondly ... still rather unclear what you want, resp. what your problem actually is. Please go read [ask]. – CBroe Mar 24 '18 at 22:24
  • Or this might in fact be just another duplicate of https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – CBroe Mar 24 '18 at 22:29

1 Answers1

0

so you could store in on the global window or document but global variables are bad and you should feel bad if you use them. :( different idea though is to have a helper script that when you call just returns that value.

`var panic_status = function(){
  return document.getElementById("panic_status").innerHTML;
}`

this way you can grab that variable from other scripts easily and reliably. (as long as the script is declared above the other ones. Then you only need to do

var myVar = panicStatus();
but maybe im misunderstanding your question?
John Hooper
  • 372
  • 2
  • 7