How do I change the value of a textarea?

  • 0
    function inWall(){
        let input2 = document.getElementById("Wall").value 
        let b = document.querySelector("textarea")
    
        if (input2.length < width * height){
            for (i = input2.length; i < width * height; i ++){  //wigth i height var переменные і работают 
                   input2 += '0' // input успешно меняется 
            }
            b.setAttribute('value', input2) // Value осталось не измененным 
        }
    }


    <div>
            <form action="">
                <textarea id = "Wall" value = "" rows = ""  ></textarea>
                
                <input  type = "button" name = "entered" value = "Submit" onclick="inWall()" ></button>
            </form>
        </div>
    JavaScript Elizabeth White, Jan 16, 2019

  • 2 Answers
  • 0
    The textarea tag has no value attribute. Use innerText

    b.innerText = input2;
    Anonymous

  • 0
    The value attribute is not equal to the value property.

    document.querySelector("textarea").value = 'bla-bla';
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!