Using this HTML code: Edit this javascript code (event-listener.js) to include a
ID: 3600516 • Letter: U
Question
Using this HTML code:
Edit this javascript code (event-listener.js) to include an EVENT LISTENER to make sure each username entered follows the label in the HTML file. (Ex-Username starts with A,B,C):
!DOCTYPE html JavaScript & jQuery - Chapter 6 EventsEvent Listener/title link rel-"stylesheet" href-"css/c06.css"> head> label for-"username1">Create a username (A-C) input type-"text" id-"usernameAC label for-"username2">Create a username (D-H) input type-"text" id-"usernameDH" label for-"username3">Create a username (I-M) input type-"text" id-"usernameI" (N-P)/label> label for-"username4">Create a username input type-"text" id-"usernameNP div id=" feedback 4"> label for-"username5">Create a username (O-2) /label> input type-"text" id-"usernameOZ"/ /Eorm> div> script src="js/event-listener.js"> bodyExplanation / Answer
Hi
Please use following javascript function for check username :
// Add checkUsername function in your all input box.
// here "A" is first letter of your range"A-C"
// here "3" is length your range"A-C" i.e A,B,C = 3,
<input type="text" id="usernameAC" name="" />
<script type="text/javascript">
function checkUsername(startChar, difflength, inputid){
var username = document.getElementById(inputid).value;// get value fron input field
var startLetter=username.charAt(0);// first letter
if(username.length == 1){
for(var i=0; i < difflength; i++){
if(startLetter.toUpperCase() == String.fromCharCode(startChar.charCodeAt() + i)){
// value match
document.getElementById(inputid).value=startLetter;
break;
}else{
document.getElementById(inputid).value="";
//when value not match then set empty value
}
}
}
};
</script>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.