I have a page with inputs with IDs language1, star1, language2, star2 etc. I need to activate the star input field if the corresponding language field has a length > 0.
Right now I’m using the code below, but I believe I should be able to solve this with a while loop or similar to avoid repeating the same code over and over. Can someone help me with this?
$('#language1').blur(function() {
if ( $('#language1').val().length == 0){
$('input[name=star1]',this.form).rating('readOnly',true);
}
else {
$('input[name=star1]',this.form).rating('readOnly',false);
}
});
$('#language2').blur(function() {
if ( $('#language2').val().length == 0){
$('input[name=star2]',this.form).rating('readOnly',true);
}
else {
$('input[name=star2]',this.form).rating('readOnly',false);
}
});
....
1 Answer