mercredi 5 février 2020

How to update 1 text box based on several others being updated (if / else if)

I am trying to update 1 textarea (output) with different text based on which text box is updated. However for some reason the only text that will populate the output text box is the first if statement. The ID's will alert as expected. I have this testing on a static document which doesnt alert at all in my fiddle, but that can be found here: https://jsfiddle.net/h6w4s50L/ all of the code is the same so I'm not sure why fiddle doesn't like it.

Original code is below:

<html>
<head>
</head>
<body>
<script type="text/javascript">
            function update(id) { 
            alert(id)
            if (id = 1){
                document.getElementById('output').value += "{panel:title=Updates}\n\n" + id.value + "\n\n{panel} \n\n";  
                } else if (id = 2) {
                document.getElementById('output').value += "{panel:title=Attached}\n\n" + id.value + "\n\n{panel} \n\n"; 
                } else if (id = 3) {
                document.getElementById('output').value += "{panel:title=Admin Updated}\n\n" + id.value + "\n\n{panel} \n\n"; 
                } else if (id = 4) {
                document.getElementById('output').value += "{panel:title=Contact Updated}\n\n" + id.value + "\n\n{panel} \n\n"; 
                } 
            }
 </script>
<form>
  <fieldset>
    <legend>Domain Update Information</legend>
    <br/>POC Updates: <br/>
    <textarea id="1" rows="7" cols="50" onchange="update(this.id)"></textarea><br/><br/>
    Authorization Letter Attached: <br/>
    <textarea id="2" rows="7" cols="50" onchange="update(this.id)"></textarea><br/><br/>
    Authorizing Authority Updated: <br/>
    <textarea id="3" rows="7" cols="50" onchange="update(this.id)"></textarea><br/><br/>
    Security Point of Contact Update: <br/>
    <textarea id="4" rows="7" cols="50" onchange="update(this.id)"></textarea><br/>
  </fieldset>
</form>

<textarea id="output" rows="20" cols="150">Domain Update Information: &#13;&#10;&#13;&#10;</textarea>
</body>
</html>

This is just a test to make sure I can get my end goal working, but it seems the issue is with the if / else if section of my script. Any assistance would be appreciated.

Aucun commentaire:

Enregistrer un commentaire