I'm wondering if this is at all possible to do...
Essentially I'm storing information of the form (i.e. select, input, textarea) within a json object.
var inputs = {
"name": {
errorMsg: "Please enter a name!",
inputName: "name",
inputType: "input"
}
}
From there, I want to construct the input value with jQuery such as:
$('input#name').val();
and have it actually return the value of the input field.
I was thinking of maybe doing something like this:
var inType = inputs.name.inputType;
var inName = inputs.name.inputName;
var stringType = $("'" + inType + "#" + inName + "'");
alert(stringType.val());
But that gives me an undefined value.
Here is the html I'm using:
<input name="name" id="name" value="test" />
I've noticed that if I add add to the json object: value: $('input#name').val() after inputType and then go alert(inputs.name.value) it gives me the proper value. So should I construct the string and then prop it to the my inputs object?