How to get value from dynamic create input in Meteor? Ask Question


#1

I have created a custom form and added some jquery for dynamic inputs, but I can’t get values from these generated inputs (Elements, Link, Image). Here are my form and code.

Template

<form id="workForm" class="workAdd">
<label>Title</label>
<input type="text" name="title" id="title" class="form-control">
<label>Live Link</label>
<input type="text" name="llink" id="llink" class="form-control">
<label>Elements Used In This Project</label>
<div class="row" id="eleContainer">
    <div class="eleRow">
        <div class="col s6 m6 l6">
            <label>Element</label>
            <input type="text" name="elements[]" id="elementsid[]" class="form-control">
        </div>
        <div class="col s6 m6 l6">
            <label>Link</label>
            <input type="text" name="elinks[]" id="elinksid[]" class="form-control" >
        </div>
    </div>
</div><!--row-->
<div class="row">
    <div class="col s6 m12 center">
        <a class="btn-floating waves-effect waves-light" id="addElements"><i class="fa fa-plus"></i></a>
    </div>
</div>
<div class="row" id="imgContainer">
    <div class="imgRow">
        <label>Image</label>
        <input type="text" name="image[]" id="imageid[]" class="form-control" >
    </div>
</div>
<div class="row">
    <div class="col s6 m12 center">
        <a class="btn-floating waves-effect waves-light" id="addImages"><i class="fa fa-plus"></i></a>
    </div>
</div>
<label>Detail</label>
<textarea id="detail" class="materialize-textarea" name="detail" data-length="120"></textarea>

<button type="submit" id="work-submit" thisId="" class="btn btn-primary">Submit</button>

Meteor And this is my submit event I have created for this form.

Template.addworkTemp.events({
"submit .workAdd": function(event) {

    var title = event.target.title.value;
    var llink = event.target.llink.value;
    var elements = event.target.elements.value;
    var elinks = event.target.elinks.value;
    var images = event.target.images.value;
    var detail = event.target.detail.value;
    return false;