How to Get the Value of Li on Dropdown Menu Click in Laravel Using Jquery

How to get the value of li on dropdown menu click in laravel using jquery?

You are querying an li, use .text() instead of .val()

$(document).ready(function(){
var liveSKUID=$("#skuvalue").text();
alert(liveSKUID);
})

You are generating a same markup each loop, causing multiple id=skuvalue which is invalid HTML.
This means you cannot use $(#skuvalue) as that will always return the first match so you have to select it positional.

I would recommend to use data-id instead as you otherwise have
multiple duplicates of a unique id

Also your sample markup is generating an invalid table, no tr or td around the rest of the data past the first td.

Assuming you have a valid HTML Table the below is an example how you might do it. If you only want the respons on clicking the specific li with the text Archieve Listing you need to give it an attribute or something to attach the click event to it.

You could go positional and assume the li is always in 2nd position but that's unreliable. As you generate the markup adding a data-id="archive" or similar shouldn't be a problem.

Ones you click on the relevant li you can go back up the DOM tree using jQuery closest('tr') to get to the current row. From there you use .find() on the matched tr to find the element with id=skuvalue. I used a attribute selector [id="skuvalue"] in the example below but I think .find('#skuvalue') should work too as you only search within the individual row's context.

$(".dropdown-menu [data-id=archive]").on('click', function() {  var x = $(this).closest('tr').find('[id=skuvalue]').text();  alert(x);})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><table>  <tbody role="alert">    <tr>      <td>        <ul>          SKU:          <li id="skuvalue">5</li>        </ul>      </td>      <td>        <div class="btn-group">          <button type="button" class="btn btn-default editSellingAttributes" data-toggle="modal" data-target="" data-id="{{$live->SKUID}}">Edit   Selling Attributes</button>          <button type="button" class="btn btn-default dropdown-toggle" data- toggle="dropdown">  <span class="caret"></span>  </button>          <ul class="dropdown-menu" role="menu">            <li><a href="#">Edit Catalogue</a></li>            <li><a data-id="archive" href="#">Archieve Listing</a></li>          </ul>        </div>      </td>    </tr>    <tr>      <td>        <ul>          SKU:          <li id="skuvalue">78</li>        </ul>      </td>      <td>        <div class="btn-group">          <button type="button" class="btn btn-default editSellingAttributes" data-toggle="modal" data-target="" data-id="{{$live->SKUID}}">Edit   Selling Attributes</button>          <button type="button" class="btn btn-default dropdown-toggle" data- toggle="dropdown">  <span class="caret"></span>  </button>          <ul class="dropdown-menu" role="menu">            <li><a href="#">Edit Catalogue</a></li>            <li><a data-id="archive" href="#">Archieve Listing</a></li>          </ul>        </div>      </td>    </tr>    <tr>      <td>        <ul>          SKU:          <li id="skuvalue">987</li>        </ul>      </td>      <td>        <div class="btn-group">          <button type="button" class="btn btn-default editSellingAttributes" data-toggle="modal" data-target="" data-id="{{$live->SKUID}}">Edit   Selling Attributes</button>          <button type="button" class="btn btn-default dropdown-toggle" data- toggle="dropdown">  <span class="caret"></span>  </button>          <ul class="dropdown-menu" role="menu">            <li><a href="#">Edit Catalogue</a></li>            <li><a data-id="archive" href="#">Archieve Listing</a></li>          </ul>        </div>      </td>    </tr>  </tbody>  <table>

How do you get the value of a dropdown list and make it an Input variable in Laravel?

You can modify it like this and use jQuery/js

<div class="container">
<form id="search_form" method="get" action="{{ route('search') }}">
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<div class="input-group">
<div class="input-group-btn search-panel">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span name="category" id="search_concept">Title</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a data-category="title" class="search_category" href="#title">Title</a></li>
<li><a data-category="author" class="search_category" href="#author">Author</a></li>
<li><a data-category="school" class="search_category" href="#school">School</a></li>
<li><a data-category="course_code" class="search_category" href="#course_code">Course Code</a></li>
</ul>
</div>
<!--<input type="hidden" name="_token" value="{{ Session::token() }}">-->
<input type="hidden" name="category" id="category"/>
<input class="form-control" name="term" placeholder="Search Here" autocomplete="off" autofocus="autofocus" type="text" id="filter">
<span id="search_submit" type="submit" class="btn input-group-addon glyphicon glyphicon-search" style="width:1%;"></span>

</div>
</div>
</div>
</form>
</div>

jQuery:

$(".search_category").click(function(e){
$("#category").val($(this).attr("data-category"));
});

Hiding an echo after clicking a dropdown tag in laravel

I guess you are not using jQuery, so I used pure javascript for the answer.

If you want to completely remove the badge then use this:
Set your <a> tag like this:

<a href="#" id="button_id" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-globe"></span>Notifications <span class="badge">{{count(auth()->user()->notifics)}}</span></a>

Then using javascript:

<script>document.getElementById("button_id").addEventListener("click", function(e){
e.preventDefault();
document.getElementById("button_id").innerHTML = "<span class='glyphicon glyphicon-globe'></span>Notifications";
});
</script>

If you want to temporarily hide the badge then:

Set your <a> tag like this:

<a href="#" id="button_id" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-globe"></span>Notifications <span id="hide_me" class="badge">{{count(auth()->user()->notifics)}}</span></a>

And use this javascript code to hide it:

<script>document.getElementById("button_id").addEventListener("click", function(e){
e.preventDefault();
document.getElementById("hide_me").style.display = "none";
});
</script>

To show it back, use:

document.getElementById("hide_me").style.display = "block";

How can I set the value of a DropDownList using jQuery?

$("#mydropdownlist").val("thevalue");

just make sure the value in the options tags matches the value in the val method.

How to get value of ul li made dropdown using php in URL by get method

There are different ways to fix that but one way to do it this way,

$('.list li').click(function(e) {  var clicked_element_value = $(this).attr("value");  var parent = $(this).parent().attr('name');  $("#" + parent).val(clicked_element_value);});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><form>  <input type="hidden" id="location" name="location" />  <ul class="list" name="location">   <li value="DELHI">DELHI</li>   <li value="MUMBAI">MUMBAI</li>   <li value="HYDERABAD">HYDERABAD</li>  </ul>
<input type="hidden" id="type" name="type" /> <ul class="list" name="type"> <li value="HOUSE">HOUSE</li> <li value="FLAT">FLAT</li> <li value="APPARTMENT">APPARTMENT</li> </ul>
<input type="hidden" id="zip" name="zip" /> <ul class="list" name="zip"> <li value="121">121</li> <li value="456">456</li> <li value="789">789</li> </ul>
<input type="hidden" id="post" name="post" /> <ul class="list" name="post"> <li value="9000">9000</li> <li value="9000">8000</li> <li value="7000">7000</li> </ul></form>

Make action of on click select box list item laravel

Route:

Route::get('/approve-user/{id}', 'AdminController@approve_user')->name('admin.approve.user');

Your view page like this:

<div class="dropdown">
<button class="btn btn-flat btn-info dropdown-toggle" type="button" id="dropdownMenu1" name="action" data-toggle="dropdown">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
@if($application->status == 1)
<li role="presentation"><a role="menuitem" tabindex="-1" href="{{ route('admin.approve.user',$application->id) }}">UnApprove</a></li>
@else
<li role="presentation"><a role="menuitem" tabindex="-1" href="{{ route('admin.approve.user',$application->id) }}">Approve</a></li>
@endif
<li role="presentation"><a role="menuitem" tabindex="-1" href="">Edit Details</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="">View History</a></li>
</ul>
</div>

Your controller page like this:

public function approve_user()
{
$id = \Request::segment(3);
$application = User::find($id);
if ($application->approved == 1)
{
$application->approved = 0;
$msg = 'User UnApproved successfully';
}
else {
$application->approved = 1;
$msg = 'User Approved successfully';
}
$application->save();
return Redirect::back()->with('message',$msg);
}


Related Topics



Leave a reply



Submit