Why is the form input type for text or password has no value attribute like input type for radio or check box. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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">

17th Feb 2019, 3:19 PM
Emmanuel Godwin
Emmanuel Godwin - avatar
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
19th Feb 2019, 8:33 AM
Ipang
+ 1
thanks
19th Feb 2019, 4:04 PM
Emmanuel Godwin
Emmanuel Godwin - avatar