event.target is undefined in events

50,600

If the event is bound on the container div then the input should be searched from target, because event.target would give you the element whom the event was attached to.

To access any value within the div you must first get access to that element and then use the properties of that element to access whatever needed - .value in this case.

Share:
50,600
Ramesh Murugesan
Author by

Ramesh Murugesan

I’m a solution-focused, self-motivated, and technically competent Technology Lead and DevOps Engineer, experienced in JavaScript, Python, PHP, Web Services, REST APIs, SDLC, CMS platforms, mobile development, AWS, Azure, CI/CD, Docker, Kubernetes, Jenkins, SQL, NoSQL, and other technologies, that believes our job is about delivering values, decreasing costs, and building solutions that perform. Matured by the knowledge gained in implementing various technical solutions as well as leading teams, I think there is no absolute right or wrong technology/stack, but the right tool for the specific job. Also, I’m willing to learn cutting-edge technologies and modern programming techniques to address technical issues and situations according to the latest trends and recommendations. Being committed professional, highly organized, and capable to work under pressure, I believe that teams should create their own explicit yet light internal process and I’m truly eager to connect with others in a collaborative environment, where ideas start to flow and that’s always the fun part.

Updated on December 30, 2020

Comments

  • Ramesh Murugesan
    Ramesh Murugesan over 3 years

    How can one use each input values in events? Hope my below code will explain you well.

    HTML:

    <template name="UpdateAge">
        {{#each Name}}
        <div data-action="showPrompt">
           <div>
              Some content
           </div>
    
           <div>
             <div>
                Some content
             </div>
           </div>
           <div>
               Name : {{name}}
               Age : <input type="text" name="age" value="{{age}}"/> //I need to access age values in event
           </div>
        </div>
    {{/each}}
    <template>
    

    JS:

    Template.UpdateAge.events({
      'click [data-action="showPrompt"]': function (event, template) {
            console.log(event.target.age.value); // TypeError: event.target.age.value is undefined
      }
    });
    

    I dont know whether my approach is good for passing parameter values to events so suggestions are welcome.