views:

5281

answers:

3

I am using MVC with C#.

I need to get the value from the hidden field of the active accordion in $(document).ready function.

A: 

Without knowing in more detail what your actual code is like, this is the closest guess I can give:

$(".ui-accordion .selected input[type=hidden]").val();

jQuery UI accordions have a "ui-accordion" class and automatically apply the "selected" class to the currently expanded accordion element.

CMerat
Below is the code that i am referring:<div class="accordion" id="accordion"> <%if (Model != null){foreach (EmpDetails _emp in Model.EmpList){%> <h3> <div class="heading_acc"> <a href="#" onclick="javascript:ShowEmployees(<%=_emp.EmpID%>);" id="aE"><b><span class="dash_title_bar_right"> <%=Html.Encode(_emp.EmpName)%></b></a> <%=Html.Hidden("EId",_emp.EmpID,new {id="EId"})%> </div> </h3> <div id="dR<%=_emp.EmpID %>"> <%=Html.Encode(_emp.EmpName)%> </div> <%}} %></div>
Prasad
i Used alert($(".ui-accordion .selected input[name$='EId']").val());It Shows undefined.
Prasad
Try alert($(".ui-accordion .selected input[name=Eld]").val())
CMerat
A: 

accordion doesn't add the class selected, but ui-accordion-content-active.

Try:

alert('value ' + $('.ui-accordion .ui-accordion-content-active input[name$=EId]').val());
Lathan
I m still getting undefined after trying this option too.it returns an object when i used $('.ui-accordion .ui-accordion-content-active input[name=EId]');but it says undefined on getting the val() of that object.
Prasad
This worked when i used like thisalert('value ' + $('.ui-accordion .ui-accordion-content-active input[name$=EId]')[0].value);
Prasad
are there more than one hidden fields that have names ending with EId?If there are try $('.ui-accordion .ui-accordion-content-active input[name$=EId]:first').val() (or replace the :first with :eq(0) (returns element with that zero-index index of the list of elements its selected)
Lathan
A: 

I have run into this "strangeness" with jQuery; it seems the selector is returning an array of objects so you have to use the "[0]" to get the element you are looking for.

Aaron Saunders