I just recently started with JS and PDF scripting, in particular, so please excuse me if this is maybe a rather basic question.
I would like to add something like a bar rating to my PDFs. I have a number of checkboxes (number varies between 5 and 15), and I would like to check all checkboxes left of an mouse up event. When a checkbox is checked already, I would like to uncheck all checkboxes right of this event.
I have managed to achived that already using uniquely named checkboxes that follow a specific naming convention (xx-1, xx-2, xx-3 etc.) Please note, this is for a rating of 1 to 5, hence the d < 6 in the loop. Still working on a way to recognize the number of boxes beforehand.
function bar(){
var [dName, dValue] = event.target.name.split("-");
if (event.target.value === "Yes") {
for (d = 1; d < dValue; d++) {
this.getField(dName + '-' + d.toString()).value = "Yes";
}
} else if(event.target.value === "Off" && dValue == 1 ){
for (d = dValue; d < 6; d++){
this.getField(dName + '-' + d.toString()).value = "Off";
}
} else if(event.target.value === "Off"){
for (d = dValue; d < 6; d++){
this.getField(dName + '-' + d.toString()).value = "Off";
}
this.getField(dName + '-' + dValue).value = "Yes";
}
}
My question is now: Can achive this using checkboxes (or similar) that share the same name but have different values? When I set it up, selecting a checkbox automatically deselects all other checkboxes like a radio button? Thinking ahead, if that is not possible, how would I use the bar information (dValue) outside the function in other fields?
Thanks for your help.
Aucun commentaire:
Enregistrer un commentaire