I have this jQuery line:
jQuery("input[name=secondname10]").removeAttr("disabled").val("");
I'd like to know how can I make the name
dynamic instead of entering it in the code as I did with name=secondname10
.
I have this jQuery line:
jQuery("input[name=secondname10]").removeAttr("disabled").val("");
I'd like to know how can I make the name
dynamic instead of entering it in the code as I did with name=secondname10
.
$('input[name=' + myNameVariable + ']')
From your comment, it's not quite clear what you want.
$('input')
.name
, you could write $('input[name]');
.secondname
you could write $('input[name^=secondname]')
.Chances are the inputs you want to target have some more convenient things in common, by which you can access them. Perhaps you're looking for all inputs in a certain container? Or all inputs with a certain class?
I suggest you read up on jQuery selectors for an idea of the different means by which you can identify a set of objects for manipulation.
Create a function that has a name parameter.
function enableInput(name) {
jQuery("input[name="+ name +"]").removeAttr("disabled").val("");
}
then you can do this
enableInput("secondname10");
if you want to do this on every input element you can do this
jQuery("input").removeAttr("disabled").val("");
if you want to do this on every input type text you can do this
jQuery("input[type='text']").removeAttr("disabled").val("");
and so on...
As you can see you have to apply the right filter to your selector.
hope this helps
you mean like tihs?
function removeAttr(nameVariable) {
$("input[name=" + nameVariable + "]").removeAttr("disabled").val("");
}