+ 7
if you talking about this function switchType(id) { var inp = document.getElementById(id); inp. type = (inp.type=='password') ? 'text' : 'password'; } the explanations is as follows: you have your input tag for the checkbox <input type="checkbox" name="show" onclick="switchType('pw')"> when clicking it, the function is called and the id of the other input box which contains the password is passed to it all the JS code does is getting the element reference using the getElementById method and changing its type attribute from password to text and vice versa
5th Oct 2017, 3:19 PM
Burey
Burey - avatar
+ 7
click on the checkbox -> the function is called -> the js code changes the input attribute "type" to password (shows *****) or to text according to the current "type"
5th Oct 2017, 3:30 PM
Burey
Burey - avatar
+ 7
he could do it without passing the "pw" and just do getElementById("pw") i guess it makes the function more generic this way tip: every one have their own style of coding don't try to understand WHY someone did something the way he/she did but rather WHAT he/she did
5th Oct 2017, 3:35 PM
Burey
Burey - avatar
+ 7
he could use it for other purposes jn this case not so much because it still does something quite specific as targeting another input element id and changing it "type" attribute again don't focus on WHY but on WHAT
5th Oct 2017, 3:53 PM
Burey
Burey - avatar
+ 6
id is sent as "pw" it makes it more generic that's all
5th Oct 2017, 3:38 PM
Burey
Burey - avatar
+ 5
master google has allll the answers 😼
5th Oct 2017, 5:29 PM
Burey
Burey - avatar