Stopping KM to Set Variable from Input in custom HTM prompt

I’m processing checkboxes and setting a variable through javascript in custom HTM prompt.
I’m trying to set KM to ignore checkboxes instead of automatically setting the variable. by adding the attribute data-ignore=1
However, the variable favorites keeps being set to 0 or 1.
I can catch my javascript result if I use different variable name instead of favorites, so the script seems to work.
I’d really appreciate if someone Can help me to fix this custom HTM prompt so KM doesn’t set the variable favorites automatically. I’m pasting my HTM entry below.
Sorry for the format. I’m not sure how to make HTM codes to show up. I just put space after and before < and >.
Thanks!

< script >
function submitIt() {
favorites = window.document.forms[‘theForm’].elements[‘favorites’]
str = “[“
for (f in favorites) {
if (favorites[f].checked) {
str+=””"+favorites[f].value+"","
}
}
str=str.substring(0,str.length-2)+"]"
window.KeyboardMaestro.SetVariable(‘favorites’, str)
window.KeyboardMaestro.Submit(‘OK’)
}
< /script >

< form name=‘theForm’ >
< input type=“checkbox” name=“favorites” data-ignore=1 value=“Apple” >Apple

< input type=“checkbox” name=“favorites” data-ignore=1 value=“Orange” >Orange

< input type=“checkbox” name=“favorites” data-ignore=1 value=“Other” >Other

< button name=“OK” type=“submit” onclick=“submitIt()” >OK< /button >
< /form >

I would suggest that you shouldn’t have KM set the variable either. In other words, don’t use the “name” property at all. When the document loads, get the value from KM and set your checkbox(es) manually. When it’s submitted, KM won’t get the value from the control.

Thanks Dan. That’s a clever suggestion.

The reason I’m using javascript to sort out the checkbox group is that KM just set 1 or 0 for each checkbox group instead of giving you the list of checkboxes are checked. Let’s say if I have checkbox groups for colors and fruits like this.

name=“fruits” value=“apple”

name=“fruits” value=“orange”

name=“fruits” value=“other”

name=“colors” value=“red”

name=“colors” value=“orange”

name=“colors” value=“other”

Even if you check two items from each group, KM will just set fruits and colors to 1. I wouldn’t know which items are checked unless I changed the name to match its value as well. But then we’ll have like 6 variables. It doesn’t really matter in this example, but if I have like hundreds of checkboxes, it would be little crazy to use hundreds of variables to track especially when I’m trying to dynamically generate the HTM form.

Thus, I’m trying to use javascript to go through each checkbox group, and set the variables to array string containing values of the checkboxes that are only checked.

Then the fruits variable will have something like [“apple”,“other”], and colors variable will have [“red”,“other”]

If I don’t use the name attribute, I wouldn’t be able to organize and go through each checkbox group using javascript though. That’s why I’m trying to set KM to ignore the form field. Theoretically if ignore-data=1 attribute works, it should solve the problem.

I’m not sure why it doesn’t work though. I tried data-ignore=1, data-ignore=true, and none of them seems to work.
Any suggestion?
Thank you for your help,

Chi

Sure you can. Use the ID property instead, and document.getElementById().

I can supply a full example if you need it.

Thanks Dan. Isn’t id attribute supposed to be unique across the document wide in html though?

Regardless, how can I make KM to ignore the field and not set the variables using ignore-data attribute?

Thanks,

Is this a KM bug?

I don’t know. But perhaps the value needs to be in quotes?

The documentation was in error, it is not “data-ignore=1” it is “data-kmignore=1”.

Thanks Peter! That worked!!!