locked
how to access the variable in jquery RRS feed

  • Question

  • User-1722422105 posted

    Hi all

    i have table like

    @if (Model.test1.Count > 0)
    {
    int cnt = 1;
    foreach (var mpl in Model.test1)
    {

    <tr data-prlid="@cnt">
    <td class="tdpraLoc">@mpl.variable1</td>


    <td id="testid">@mpl.variable2 </td>

    <td>

    <a href="javascript:void(0)" class="btn btn-danger p-l-sm btnDelPracloc">Delete</a>
    </td>
    </tr>
    cnt++;
    }
    }

    i have code for access  in js like

    var practicename_ = $('.tdpraLoc').val();
    var locationname_ = $('#testid').val();

    but it is show as practicename_ and locationname_  is undefined

    please help me

    Tuesday, August 7, 2018 10:40 AM

All replies

  • User-821857111 posted

    Use val() to get values from form fields. If you want to get the content of a td (or other element) use text() for plain text or html() to get the innerHTML:

    var practicename_ = $('.tdpraLoc').text();
    var locationname_ = $('#testid').text();

    Tuesday, August 7, 2018 12:35 PM
  • User1204533129 posted

    make sure you have Jquery library files included(min.js) and

    try :

    var practicename_ = $('.tdpraLoc').val();
    var locationname_ = $('#testid').val();

    if it doesnt work try : 

    var practicename_ = $('.tdpraLoc').text();
    var locationname_ = $('#testid').text();

    Best Regards,

    Kamal

    Thursday, October 4, 2018 7:46 PM