0

I am trying to pass value to html id attribute. So, I am getting value from laravel php controller

Javascript

        $("ul.nav-tabs > li > a").click(function() {
        // alert($(this).attr("href").replace("#", ""))
        var id = $(this).attr("href").replace("#", "");
        console.log(id);

        if(id) {
            $.ajax({
                url: "{{ route('user.schedule.getId') }}",
                type: "GET",
                data:{'id':id},
                dataType: "json",
                success:function(data) {
                    console.log(data);

                }
            });
          }
       });

html Blade

                     <ul class="nav nav-tabs tabs_content">
                            @foreach ($routes as $route)
                                <li >
                                    <a href="#{{ $route->id }}" id="ad" data-toggle="tab">
                                        {!! $route->name !!}
                                    </a>
                                </li>
                            @endforeach
                        </ul>
                        <div class="tab-content blog_tabs">
                            <div class="tab-pane" name="schedule" id="tab-{{ $route->id}}" >

                                @foreach ($tabSchedule as $schedule)
                                    <ul class="list-group">
                                        <li class="list-group-item">{{ $schedule->schedule_number}}</li>
                                    </ul>
                                @endforeach    
                            </div>
                        </div>

so here is picture of what i want to pass:

enter image description here

2 Answers 2

1

Query the element and set the id attribute:

success: function(data){
     $('.tab-content .tab-pane').attr('id', data.id)
}

But I don't get it. Why are you dynamically setting an id when you can do it in something a bit more acceptable like in a class, or a custom attribute eg data-id. And then just access the element through the class or attribute

Sign up to request clarification or add additional context in comments.

Comments

1

You could give your hidden field a unique id for example:

<input type="hidden" name="smname" id="smname" />
and then in javascript:

document.getElementById('smname').value = data();
I hope I have helped you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.