asp.net - Uncheck a radio button in case another one is checked in a ListView using jQuery -



asp.net - Uncheck a radio button in case another one is checked in a ListView using jQuery -

i have list of radio buttons generated dynamically listview. each radio button refers id of different image.

now instead of checking radio button want user able click on image instead , radio button checked automatically. far good. i've reached stage.

however want user check 1 image, means if new image clicked radio button of previous ones must unchecked. tried many ways none worked. here script:

$(document).ready(function () { $(function () { $(".smallsquarephoto").click(function () { var radiovalue = $(this).attr("myattribute"); //get value of myattribute $('input[myattribute=' + radiovalue + ']').attr('checked', 'checked'); //check radiobutton corresponds image clicked $("#smallsquarephoto" + radiovalue).css("border-color", "#51cf25"); //create greenish border around selected image $('[id^="smallsquarephoto"]:not(#smallsquarephoto' + radiovalue + ')').css("border-color", "white"); //remove greenish border previous image selected $("#<%=formview3.findcontrol("updatebutton").clientid %>").removeattr('disabled'); //enable alter button in case image clicked // far //here want uncheck radio buttons don't correspond latest clicked image. how? }); }); }); <itemtemplate> <div id="smallsquarephoto<%# eval("id_bg") %>" class="smallsquarephoto" style="cursor:pointer; border-width: 4px; background-image: url(/members/images/background/<%# eval("bg_filename") %>)" myattribute='<%# eval("id_bg") %>' > <input id="radio1" name="bg_list" type="radio" runat="server" myattribute='<%# eval("id_bg") %>' value='<%# eval("bg_filename") %>' /> </div> </itemtemplate>

and here html output

<div id="smallsquarephoto269" class="smallsquarephoto" style="background-image: url(150301-110930-1.jpg )" myattribute='269' > <input value="150301-110930-1.jpg " name="ctl00$contentplaceholder1$listview1$ctrl0$bg_list" type="radio" id="contentplaceholder1_listview1_radio1_0" myattribute="269" /> </div> <div id="smallsquarephoto266" class="smallsquarephoto" style="background-image: url(150301-110104-1.jpg )" myattribute='266' > <input value="150301-110104-1.jpg " name="ctl00$contentplaceholder1$listview1$ctrl1$bg_list" type="radio" id="contentplaceholder1_listview1_radio1_1" myattribute="266" /> </div>

update solution next script:

$(document).ready(function () { $(function () { $(".smallsquarephoto").click(function () { var radiovalue = $(this).attr("myattribute"); //get value of myattribute $('[id^="smallsquarephoto"]:not(#smallsquarephoto' + radiovalue + ')').css("border-color", "white"); //remove greenish border previous image selected $("#<%=formview3.findcontrol("updatebutton").clientid %>").removeattr('disabled'); //enable alter button in case image clicked $('input[type=radio]').prop('checked', false); //new $('input[myattribute=' + radiovalue + ']').prop('checked', 'checked'); //new $("#smallsquarephoto" + radiovalue).css("border-color", "#51cf25"); //create greenish border around selected image }); }); });

you can seek this

$(document).ready(function () { $(function () { $(".smallsquarephoto").click(function () { var radiovalue = $(this).attr("myattribute"); //get value of myattribute $('[id^="smallsquarephoto"]:not(#smallsquarephoto' + radiovalue + ')').css("border-color", "white"); //remove greenish border previous image selected $("#<%=formview3.findcontrol("updatebutton").clientid %>").removeattr('disabled'); //enable alter button in case image clicked $('[id^="smallsquarephoto"]').prop('checked', false); $('input[myattribute=' + radiovalue + ']').prop('checked', 'checked'); //check radiobutton corresponds image clicked $("#smallsquarephoto" + radiovalue).css("border-color", "#51cf25"); //create greenish border around selected image }); }); }); <itemtemplate> <div id="smallsquarephoto<%# eval("id_bg") %>" class="smallsquarephoto" style="cursor:pointer; border-width: 4px; background-image: url(/members/images/background/<%# eval("bg_filename") %>)" myattribute='<%# eval("id_bg") %>' > <input id="radio1" name="bg_list" type="radio" runat="server" myattribute='<%# eval("id_bg") %>' value='<%# eval("bg_filename") %>' /> </div> </itemtemplate>

i'm not sure think it's helpful you.

jquery asp.net radio-button

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -