If you want to return the value of the element with the specified id, then yes, since this is what seems to be the logical goal of your function:
function f(id){ return $("#" + id).val(); }
Functions should assume that there is an element with the specified identifier, and then it returns the value of this element. This should work for input fields as well as textarea . If, however, this is any other element, you can use html() or text() instead of val() for example:
function f(id){ return $("#" + id).html();
source share