I created a form that accept text input in the field. there’s 2 way to submit it. by pressing enter or clicking the submit button.
enter is fine but when i used the submit button it gives me undfined value.
here is the code:
body.html
<body>
<h1>Welcome</h1>
{{> blog}}
</body>
<template name="blog">
<form class="new-blog">
<label>Title</label>
<input type="text" placeholder="text" name="title">
<button type="button" class="submit-button">Submit</button>
</form>
</template>
body.js
Template.blog.events({
'submit .new-blog'(e) {
e.preventDefault();
var title = e.target.title.value;
Blogs.insert({
title: title
});
alert(title);
},
'click .submit-button'(e) {
e.preventDefault();
var title = e.target.title.value;
Blogs.insert({
title: title
});
alert(title);
},
});
thanks in advance