This is a sample javascript code to alert the user if he clicks shift + 1 (or 2,3...9)
But as you see this code is almost the same.
a = window.event.keyCode;
var b = window.event.shiftKey
if (a == 49 && b) {
alert(document.getElementById('alert1').length)
}
if (a == 50 && b) {
alert(document.getElementById('alert2').length)
}
if (a == 51 && b) {
alert(document.getElementById('alert3').length)
}
if (a == 52 && b) {
alert(document.getElementById('alert4').length)
}
if (a == 53 && b) {
alert(document.getElementById('alert5').length)
}
if (a == 54 && b) {
alert(document.getElementById('alert6').length)
}
if (a == 55 && b) {
alert(document.getElementById('alert7').length)
}
if (a == 56 && b) {
alert(document.getElementById('alert8').length)
}
if (a == 57 && b) {
alert(document.getElementById('alert9').length)
}
Is there any javascript (it can be jQuery) code (using for(){}
method or something else) that will do the same job by writing less code and the other code to be generated by the browser and executed when is required?