dropdown using ajax data fetch

Posted 1 month ago by Van1310

i have 2 tables

  1. job -> job,
  2. jobtitle -> city

i want to fetch citywise job in dropdown

here my blade file

<label for="exampleSelect1">City</label>
<select class="form-control m-input" id="city" name="city" onChange="getCity(this.value);">
    <option value="bhavnagar"> Bhavnagar </option>
            <option value="ahmedabad"> Ahmedabad </option>
</select>

<label for="exampleSelect1">Job Title</label>
<select class="form-control m-input" id="jobtitle" name="jobtitle" >
    @foreach($jobtitle as $job)
        <option value="{{$job->jobtitle}}"> {{$job->jobtitle}} </option>
    @endforeach
</select>

here is my ajax code

<script>
    function getCity(val) {
    $.ajax({
        type: "POST",
        foreach($jobtitle as $job)
            {
                url: "{{route('job.store',['id'=>$job->id])}}",
                data:'jobtitle_id='+val,
            }   
        success: function(data){
        $("#city").html(data);
        }
    });
}
</script>

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.