Rayman Bacchus Rayman Bacchus - 1 year ago 50
Javascript Question

Get value of li on click using JQuery

This is my first question here, so forgive me is asked incorrectly.
I have an html view:

<div class="input-group-btn search-panel">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span id="search_concept">Filter by</span> <span class="caret"></span>
<ul class="dropdown-menu" role="menu" id="mysearch">
<li><a href="/Home/SearchPlayersRegForm" id="Searchstr" >Registration Number</a></li>
<li><a href="/Home/SearchPlayersView" id="LastName">Last Name Only</a></li>
<li><a href="/Home/SearchPlayersView" id="FullName">Child's First and Last Name</a></li>
<li><a href="/Home/SearchPlayersView" id="Pho">Phone Number</a></li>

<input type="text" class="form-control" name="Searchstr" id="Search" placeholder="Search term...">
<span class="input-group-btn seach-form">
<button class="btn btn-default" onclick="PerformSearch(event)" id="Searchstr"><span class="glyphicon glyphicon-search"></span></button>

and i want to use a JQuery to find the value in the li

function PerformSearch(event) {
alert('I AM HERE')
var btn_name = $(document).attr('class')
var OptionForm = $(document).closest('li').attr('id');
alert(btn_name + " within " + id);};

am i doing this completely wrong? I go to the function but I can't get the function to pull the id in the li.


I would suggest that use a class.

Then use jquery to check if the class has been clicked, and then use something like data-livalue to get the value of the href which you can pass.


in jquery do as follows:

        var vref =   $(this).data('livalue')
        # windows.location.href = vref