PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] Laravel select dropdown using ajax

 January 24, 2022     ajax, eloquent, laravel, laravel-5     No comments   

Issue

I have data in an array that contains hotels' names with their id. I want to place them in my select where I will display only the city an grab the id to do ajax and display rooms name. The problem is it is displaying both the name of the hotel and the id array in my dropdown. this is my controller.

 foreach ($hotel as $nam ){
   $hotel_nam[]=$nam->id;
   $hotel_nam[]=$nam->hotel_name;             
  }
  return  $hotel_nam;

this is my drop down

  {!! Form::select('hotel_name',$hotel_nam,'S', array('style'=>' Border:none; ', 'id' => 'hotel_id', 'onchange'=>"showRooms(this.value)"));!!}

Solution

$hotelLists = [''=>'--Select Hotel--'];
foreach ($hotel as $nam) {
    $hotelLists[$nam->id] = $nam->hotel_name;
}

{!! Form::select('hotel_name',$hotelLists,'', array('style'=>' Border:none; ', 'id' => 'hotel_id', 'onchange'=>"showRooms(this.value)"));!!}


Answered By - Md Abdul Awal
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing