Call A Global Variable Into Two Functions Using Javascript
I have a global variable: var x = document.getElementById('Node').value;  Where the value is determined by a text box with the ID of 'Node'. I have two functions that don't same th
Solution 1:
You can simply use:
window.x = document.getElementById("Node").value;Solution 2:
Try this
(function() {
    var x = document.getElementById("Node").value;
    document.getElementById("Node").onchange = function() {
      myNode()
    };
    document.getElementById("mySelect1").onchange = function() {
      myNotes()
    };
    document.getElementById("mySelect2").onclick = function() {
      summary()
    };
    
     functionmyNode() {
      x = document.getElementById("Node").value;
    }
    functionsummary() {
      var a = document.getElementById("mySelect1").value;
      var b = document.getElementById("mySelect2").value;
      document.getElementById("5").value = a + " - " + b + " - " + x;
    }
    functionmyNotes() {
      var a = document.getElementById("mySelect1").value;
      var b = document.getElementById("mySelect2").value;
      document.getElementById("4").value = a + " + " + b + " + " + x;
    }
  }
)();Notes : <inputtype="text"id="4" /><br> Summary : <inputtype="text"id="5" /><br><selectid="Node"><optionvalue="w">w
  <optionvalue="x">x
  <optionvalue="y">y
  <optionvalue="z">z
</select><selectid="mySelect2"><optionvalue="a">a
  <optionvalue="b">b
  <optionvalue="c">c
  <optionvalue="d">d
</select><selectid="mySelect1"><optionvalue="1">1
  <optionvalue="2">2
  <optionvalue="3">3
  <optionvalue="4">4
</select>
Post a Comment for "Call A Global Variable Into Two Functions Using Javascript"