New course! Every coder should learn Generative AI!
Try a free lesson0
Why is the form input type for text or password has no value attribute like input type for radio or check box.
<input type="text" name="username"/> THEN <input type="radio" name="male" value="male">
2 Answers
+ 2
They do have such attribute, here's a little example for you to play with. Mind you though, it is not recommended to assign a value to a password input unless you know what you're doing : )
<!DOCTYPE html>
<html>
<head>
<title>Text and password</title>
</head>
<body>
<input type="text" id="text1" value="The text" />
<button onclick="showText()">Show Text</button>
<input type="password" id="pwd1" value="1234" />
</body>
<script>
function showText() {
var text = document.getElementById("text1").value;
var password = document.getElementById("pwd1").value;
alert("Text: " + text + "\nPassword: " + password);
}
</script>
</html>
Hth, cmiiw
+ 1
thanks