An html element can be clicked, touched, etc. depending on the device using it. Is there any way to handle them all without them crashing into each other? I used onpointerup but the label's for doesn't trigger it. Also, I need to pass the input element to the function. I have hundreds of these so I'm looking for a general solution. When I use onpointerup on a radio or checkbox input and the user checks it, the onpointerup function reads it as false. If the user clicks it again, it'll read true. It's backward. This tells me that when the first onpointerup fires the checkbox gets checked but not until after the onpointerup executes. How can I create a 'click' event (click, touch, etc) that will fire once if the input or the label is clicked, touched or what else - and - recognize any change (ie checked) in the input as a result of the event? <button onWHAT="doMyClick();" value="Click, Touch, Whatever Me" > Code (markup):
I actually almost edited it but didn't. OK now how do I make it work on all device types using click or touch or iduno voice command? <input id='ckTest' type="radio" onWHAT="doMyClick(this);" value="1" > <label for='ckTest' >Check the input</label> Code (markup):
Hmm. I've never heard of HTML attribute ONWHAT before. This is the reason why some of your devices / browsers don't understand your line, perhaps? AFAIK, for INPUT element of type RADIO, you may use ONCLICK instead and test element's CHECKED attribute.
Be warned I've had onclick not fire for input when you click on their label. You are using <label> like a good little doobie, right? In the case of checkboxes and radio sets, you might want to look at onchange and/or oninput... though the latter is more useful for actual text based inputs. And seriously, don't say onevent in your markup. It means you need a global scope function. It's called addEventListener, use it; this isn't 1997 no matter what the "framework stupid" gimboids claim. If the element itself is scripting only functionality, it probably doesn't belong in the markup either.
Thanks for the response Jason: "You are using <label>" yes on your previous recommendations. "don't say onevent in your markup" I put php -> javascript -> html all in the same file for one page (interface) with few exceptions. So, most of my javascript functions are global. Global scope is that page which is fine. I have cases where I use objects but the markup recognizes them: onclick='IfcUser.getRec(this.dataset.id);'. addEventListener is more work and adds code. I don't see the upside. "look at onchange and/or oninput" If I use an input or change event and the user clicks the label the function doesn't fire. Calling the function from the label doesn't work because the function needs the element or a value from it. "element itself is scripting only functionality" ah you know that trick. It's rare but I can't say I've never done it. I try to stick to dataset attributes.