Showing posts with label array push and join. Show all posts
Showing posts with label array push and join. Show all posts

Friday, August 25, 2017

jQuery push multiple values in input tag


Just set value to input store it in some temporary variable, append the value you want to store and set the value of input to this temporary variable eg.

<input id="user" type="text" name="user" class="form-control" />
<input id="user_id" type="hidden" name="user_id" value="" />

var oldValue = $("#user_id").val();
var arr = oldValue === "" ? [] : oldValue.split(',');
arr.push(yardval);
var newValue = arr.join(',');
$("#user_id").val(newValue);