asp.net - jquery not finding any attribute values -


in code below i'm trying change value of hiddenfield when checkbox clicked (in order access code behind later). however, when try value using jquery below, 'undefined' attribute i've tried. i've assumed means i've not managed find element i'm looking for, there no attribute show.

any ideas on i'm going wrong? i've little experience jquery, while not complete noob, i'm not fluent, there's obvious i'm missing.

thanks in advance.

html

    <asp:gridview id="promqs" runat="server" showfooter="true" datasourceid="promqdat" autogeneratecolumns="false" onrowdatabound="promqs_rowdatabound">     <columns>         <asp:templatefield headertext="very unsatisfied" headerstyle-cssclass="regtext ans promhead">             <itemtemplate>                 <div id="thang" class="thang">                     <asp:checkbox id="vunsat" runat="server" checked="true" />                     <asp:hiddenfield id="hiddenfield" runat="server" value="toot" />                 <ajaxcontroltoolkit:mutuallyexclusivecheckboxextender id="mecb1" runat="server" targetcontrolid="vunsat" />                 </div>             </itemtemplate>         </asp:templatefield>    </columns> 

and jquery

        $(document).ready(function () {         $(this).click(function (event) {             var el = event.target.id;             var div_id = $(el).closest('div[id]').attr('id');             var hf_id = $(el).closest('div[id]').find('.thang').attr('value');             alert(div_id);             alert(test);         });     }); 

i guess need change:

$(el)  

to

$('#'+el) 

and event.target not target element think. line:

var hf_id = $(el).closest('div[id]').find('.thang').attr('value'); 

would absolutely return undefined because thang doesn't have value attribute.


i'm trying change value of hiddenfield when checkbox clicked

to answer this, suggest use change event on checkboxes:

$(document).ready(function() {   $('input[type="checkbox"]').change(function(event) {     var el = this; // checkbox     var div_id = $(el).closest('div[id]').attr('id'); // returns "thang"     var hf_id = $(el).siblings('input[type="hidden"]').val(); // hidden input     alert(div_id);     alert(test);   }); }); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -