1

I need help on how I could simulate a keypress/keydown, specifically spacebar when clicking on a label. I need to do it with only javascript or mootools, no jquery please.

I'm using a script I found for a dropdown with multiselect. What I need to do is that when they select one of the options in the dropdown this one is selected as well on the checkboxes on the bottom. I added an event change in order to do this, but it's not working correctly since the script for the multiselect is moving the inputs into an <li> tag and adding a label. (Here is the link)

I already tried adding an event click to the <li> and label without luck. I also tried to add a fireEvent to the label and li. If you click the checkbox on the dropdown the event works correctly or if you hit spacebar. So I've run out of solutions to this problem. Any ideas? I would really appreciate any tips on how to do this.

Sergio
  • 28,539
  • 11
  • 85
  • 132
  • *"specifically spacebar when clicking on a label"* Please elaborate. This doesn't make sense. How would you combine a click with spacebar key press? – Artjom B. Jul 18 '14 at 19:12
  • This might help: http://stackoverflow.com/q/10455626/1816580 – Artjom B. Jul 18 '14 at 19:21
  • When I click a label, I want to simulate that the spacebar is being pressed. I hope this is clear. Is this possible without using jquery? Just with javascript/moootools? Thanks I will take a look at that link – Cesar Silva Jul 18 '14 at 20:44
  • Hi Cesar, welcome to Stackoverflow. Do you want to create a syntetic `keydown` event or inser a empty space on a text input? Could you be more clear? – Sergio Jul 18 '14 at 21:17
  • Hi Sergio, thanks for the welcome. Sure, actually the keydown event is just a solution for another problem. Let me explain what I want to do, I'm using a script I found for a dropdown with multiselect. What I need to do is that when they select one of the options in the dropdown this one is selected as well on the checkboxes on the bottom. I added an event change in order to do this, but it's not working correctly since the script for the multiselect is moving the inputs into an
  • tag and adding a label. Here is the link: http://s.onesurvey.com/extwix/test_p181584802.aspx?__etk=BEYNDCPLPLEV
  • – Cesar Silva Jul 18 '14 at 21:47
  • I already tried adding an event click to the
  • and label without luck. I also tried to add a fireEvent to the label and li. If you click the checkbox on the dropdown the event works correctly or if you hit spacebar. So I've run out of solutions to this problem. Any ideas?
  • – Cesar Silva Jul 18 '14 at 21:55
  • @CesarSilva not sure still what you want, but to check the correspondent checkbox each time one in clicked, maybe something like this: http://jsfiddle.net/28Dt5/ - based on your id names this would work for more groups if you keep the same pattern. – Sergio Jul 19 '14 at 08:29
  • @Sergio sorry, I haven't tested it yet, let me try later today and will let you know how it went. But yeah, I just want to check the corresponding checkbox on the bottom when I click on the options on the dropdown. Thanks – Cesar Silva Jul 23 '14 at 15:24