Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/disable textarea after taking input from keyboard

I have a textarea which is disabled by default. And then on press of 'Edit' I take some input from user. If it is valid, I want to enable the textarea. Here is the code which I have right now:

<textarea name="comment" cols="5" rows="2" disabled="true"><%= $tmp_com %></textarea>
<a href="javascript:validateUser()">Edit</a>

function validateUser(){
var name=prompt("Please enter the password");

    if (name=="1234")
    {
       document.getElementByName("comment").disabled="false";
    }
}
like image 842
Pi Horse Avatar asked Nov 28 '22 16:11

Pi Horse


1 Answers

There is no getElementByName in JavaScript. Easiest solution, add an id, and use getElementById.

<textarea name="comment" id="comment" cols="5" rows="2" disabled="true">

and JavaScript

document.getElementById("comment").disabled="false";
like image 120
epascarello Avatar answered Dec 05 '22 08:12

epascarello