Why do php form arrays behave strangely/(unexpectedly) in jQuery -
why php form input arrays act funny in jquery?
is there way overcome this?
hi, wrote code , works.. updating form of 21 radio inputs emphasize label next checked radio(s).
*visually - not in html tag
$(function() { for(count = 0;count<21;count++) { result = $("input:radio[name=choice"+count+"]:checked").val(); $("input[name=\"choice"+count+"\"][ value=\""+ result +"\"]").attr("class", "magic"); $("div.radio:has(input.magic)").attr("class", "radio spell"); } $("input").click(function() { $("div.radio:has(input.magic)").attr("class", "radio"); $("input.magic").removeattr("class", "magic"); var count = 0; var result = 0; for(count = 0;count<21;count++) { result = $("input:radio[name=choice"+count+"]:checked").val(); $("input[name=\"choice"+count+"\"][ value=\""+ result +"\"]").attr("class", "magic"); $("div.radio:has(input.magic)").attr("class", "radio spell"); } }); });
here css
input[type="radio"] { height: 20px; } input[type="radio"] + label { color: #777; font-weight:100; letter-spacing: 1px; } input[type="radio"].magic + label { color: black; font-style: italic; /*text-decoration:underline;*/ font-weight: 600; letter-spacing: 0px; text-align: center; display:inline-block; width: 80px; } div.radio.spell { border: outset white 2px; }
now radio names used choice0 - choice20 , works ok.
before used choice[0] - choice[20] , did not work @ all. behaved weird.
the jquery code like: result = $("input:radio[name=choice["+count+"]]:checked").val(); ...
i wondering, there anyway around that?
thank valuable input.
[
, ]
used attribute selectors in jquery, need escape them use them part of string: $(":radio[name=choice\["+count+"\]]")
.
that said, rather uncomfortable way of manipulating element groups. easy way create html structure reflects groups, , use find other members of group:
$(function() { $(":radio[name^=choice]:checked").each(function() { $(this).closest('div.radio').attr("class", "radio spell") .find("input[name^=choice]").attr("class", "magic"); }); });
etc.
Comments
Post a Comment