I am using js to fetch data from a form. I want only to get the value from <input type="text" name="postid"> into the postid variable.
Here is my code. I have added a comment where I want the value. (var postid= ? //Here).
$('#comment_form_sub').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
//var postid= ? //Here
console.log(form_data);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="comment-form inline-items" method="POST" id="comment_form_sub">
<input type="text" name="postid" id="postid" value="23">
<input type="text" name="comment_content" id="comment_content" class="form-control input-sm" placeholder="Press enter to post comment">
<input type="submit" style="display: none;" />
</form>
How can I get the value from the postid input into my variable?
$("#postid").val()