I could not say exactly what you wanted. It looks like you want the ID and value new hidden input be the vals value. Is it correct?
var $hiddenInput = $('<input/>',{type:'hidden',id:vals,value:vals});
Then you add it wherever you want.
$hiddenInput.appendTo(selector);
EDIT:
For clarification, selector is a reference to the element into which you want to add a new entry.
If you want to add it to the body tag, follow these steps:
$hiddenInput.appendTo('body');
If you want to add it to an element with someClass class, do:
$hiddenInput.appendTo('.someClass');
user113716
source share