Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery variable in input name selector [closed]

I want to use variable in jquery selector to choose checked input and my code is below. what is wrong here?

function MyFunction(MyVariable){
var idAddress = $("input[name='id_address_" +MyVariable+ "']:checked").val();
alert(idAddress);
}
like image 396
tebdilikiyafet Avatar asked Jun 26 '26 12:06

tebdilikiyafet


1 Answers

Syntactically, what you have is correct. It would get any inputs that have the name id_address_ + MyVariable that are checked, and then get the value of the first element, if multiple are returned. If the value of idAddress is null, then you are not getting anything returned from jQuery based on your selection criteria. For that we would need some more code to see the form elements, where MyVariable comes from, etc.

like image 134
John Niedzwiecki Avatar answered Jun 30 '26 11:06

John Niedzwiecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!