I have a problem, I need to obtain the values for html elements by name using Jquery ussually I would do it like this $("input[name=form_size]).val(); but what if my name attr value looks like this name="data[referralMedium][referral_id]" how do I write the JQuery code?
4 Answers
You need to put quote marks around it:
$("input[name='data[referralMedium][referral_id]']").val();
Note that technically the quote marks are always required. See the docs for the attribute equals [name="value"] selector.
4 Comments
FreeCandies
In addition, you can create your own selector like #id, .class etc. Say for example you want $("--some_name") to return the elements with the name "some_name". This is possible to achieve with a custom selector.
Elitmiar
So this will then also work if($("input[name='data[ReferralMedium][referral_id]'] option:selected").val() == 13){
lonesomeday
@Roland How can an
input have a descendant option?Elitmiar
@lonesomeday - My Bad, it should be select not input