try it
var q = $("#question").val(); var x = $("input[name='" + q + "']").val();
in the second line, the q variable, the name represented at the input with id 'question', will be enclosed in 'and may contain any supported characters, such as space,:, - etc.
If you need the value of a component regardless of its tag, you can do this:
var x = $("[name='" + q + "']").val();
Note that this approach $("[name='" + q + "']")
can return more than one element, but .val()
returns only the value of the first element.
source share