JavaScript meteor.js - pass id of element clicked to a collection

I've built a page with 3 elements, each of which looks like this:

<div class="col-md-4 event-type">
<a target='_blank' href="{{ pathFor 'step2' }}" id="eventchoice" name="eventchoice" value="corporate">
</a>
</div>

I'm trying to pass the value or name or id of the the <a> element on to a collection using the following code:

EventsController.events({
    'click #eventchoice' : function(event) {
        console.log(event.target.getAttribute("id"));
        console.log(event.target.getAttribute("name"));
        console.log(event.target.getAttribute("value"));

        var eventchoice = event.target.value;   
        var params = {
            eventchoice: eventchoice 
        }

        //Insert Event
        Meteor.call('addEvent', params);
        FlashMessages.sendSuccess('Event Added');
    }
});

I added the console.log's to see if I can get the id/name/value of the <a> element, but the console outputs 'null' for all of these. Therefore, there is nothing to pass to the collection in the eventAdd method.

I don't believe the problem is with the EventsController, the addEvent method or the Events collection. Any ideas how I can pass these values through?

Thank you for your help!

Answer:1

I think there must be something wrong with your controller then, because if you check the Meteorpad here, it works just fine. Although you might want to use a class instead of an id if you have many similar elements.

Answer:2

is there an elegant way to determine, whether an array like this: [ {id: 1, value: false}, {id: 2, value: true}, {id: 3, value: false}, {id: 4, value: true}, {id: 5, value: true} ] ...

is there an elegant way to determine, whether an array like this: [ {id: 1, value: false}, {id: 2, value: true}, {id: 3, value: false}, {id: 4, value: true}, {id: 5, value: true} ] ...

  1. check whether array a is a permutation
  2. check whether array is empty javascript
  3. check whether array is empty
  4. check whether array contains element javascript
  5. check whether array is empty java
  6. check whether array is empty python
  7. check whether array contains element java
  8. check whether array a is a permutation c#
  9. check whether array is sorted or not
  10. check whether array a is a permutation in java
  11. check whether array is palindrome or not
  12. check whether array contains duplicates
  13. check if array is empty javascript
  14. check if array is empty php
  15. check if array is empty
  16. check if array contains value javascript
  17. check if array is empty python
  18. check if array contains value
  19. check if array javascript
  20. check if array is empty java

I am having a problem where i'm trying to render pass an array's data to a card component but it doesn't appear on the page, the card component renders normally on its own: import React, { Component }...

I am having a problem where i'm trying to render pass an array's data to a card component but it doesn't appear on the page, the card component renders normally on its own: import React, { Component }...

  1. array does not contain
  2. array does not include javascript
  3. array does not contain javascript
  4. array does not name a type
  5. array does not contain java
  6. array does not contain a definition for cast
  7. array does not include ruby
  8. array does not contain python
  9. array does not contain a definition for empty c#
  10. array does not contain swift
  11. array does not name a type arduino
  12. array does not contain a definition for tolist
  13. array does not contain mongodb
  14. array does not name a type c++
  15. array does not contain powershell
  16. array does not contain c#
  17. array does not contain postgres
  18. array does not contain js
  19. array does not contain sql
  20. @array doesn't match its definition

If I defined some variable in outer closure, and in the inner closure has defined another variable with the same name. Can I somehow get the outer variable? I know it's still somewhere in the memory ...

If I defined some variable in outer closure, and in the inner closure has defined another variable with the same name. Can I somehow get the outer variable? I know it's still somewhere in the memory ...

I've got a simple directive—<call-card>—and I'm wondering how to apply one-time bindings to it, as practice to optimize future directives. This directive's definition object looks like: { ...

I've got a simple directive—<call-card>—and I'm wondering how to apply one-time bindings to it, as practice to optimize future directives. This directive's definition object looks like: { ...