Rayman Bacchus Rayman Bacchus - 7 months ago 26
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>
</button>
<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>
</ul>
</div>

<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>
</span>
</div>


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.

Answer

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:

        $('.liclickedclass').click(function(){
        var vref =   $(this).data('livalue')
        alert(vRef)
        # windows.location.href = vref 
        });