I have an input element of type password which is inside a <td>
with id type="pass"
. I want to change the type of the input element inside that <td>
to type="text"
using javascript, how would I go about doing this? I also made a checkbox with onclick()
events to toggle showing password.
Sorry I'm just a beginner and just started learning javascript a few days ago.
Below is my sample code:
<tr>
<td><input type="text" name="username"></td>
<td id="pass"><input type="password" name="password"></td>
<td><input type="checkbox" onclick="showPass()"></td>
</tr>
All I know is directly changing the input type using javascript provided that the input element has the id.
Here is my javascript:
function showPass(){
var x = document.getElementById("pass");
if(x.type === "password"){
x.type = "text";
}else{
x.type = "password";
}