9 Replies - 572 Views - Last Post: 20 March 2019 - 01:47 AM Rate Topic: -----

#1 DanZman   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 24-January 18

Apending to a route JS - Using Larvel

Posted 14 March 2019 - 12:41 PM

I'm trying to append an id to this route in my blade file:
  <div class="clickable-element col-lg-3 col-md-6 location-tile js-location-id" data-href="{{ route('report.file.details', ['id']=>'id') }}"></div>


Here is my JS code:
  $locationTile.find('.js-location-id href').replace('id',this.locationId);



My JS builds a locationTile object by looking at the html tags with the specific classes in the "find()" method above.

Any help is appreciated.

Thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: Apending to a route JS - Using Larvel

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3814
  • View blog
  • Posts: 13,870
  • Joined: 08-August 08

Re: Apending to a route JS - Using Larvel

Posted 14 March 2019 - 06:41 PM

Looks to me like you've misplaced a bracket. Try
  <div class="clickable-element col-lg-3 col-md-6 location-tile js-location-id" data-href="{{ route('report.file.details', ['id'=>'id']) }}"></div>

Was This Post Helpful? 0
  • +
  • -

#3 DanZman   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 24-January 18

Re: Apending to a route JS - Using Larvel

Posted 18 March 2019 - 02:33 PM

I'm trying to grab this laravel route with javascript and saving it a variable but I'm having trouble doing so.

div class="clickable-element js-location-id" data-href="{{ route('report.file.list')}}">DATA</div>


I don't want to build a URL object, I'm trying to grab this existing route with javascript and add one parameter to it. Please help!
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14987
  • View blog
  • Posts: 59,843
  • Joined: 12-June 08

Re: Apending to a route JS - Using Larvel

Posted 18 March 2019 - 02:40 PM

Merging duplicate topics.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3814
  • View blog
  • Posts: 13,870
  • Joined: 08-August 08

Re: Apending to a route JS - Using Larvel

Posted 18 March 2019 - 04:49 PM

You don't seem to understand that PHP is server side and Javascript is client side. That means you either have to build the Javascript with php or use javascript to grab the link. If you give your div an id the Javascript could look like this:
var myLink = document.getElementById("myLinkedDiv");
var myURL = myLink.href; 


Was This Post Helpful? 1
  • +
  • -

#6 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Apending to a route JS - Using Larvel

Posted 19 March 2019 - 01:49 AM

In jQuery that would be $('#myLinkedDiv') but you could not then do $('#myLinkedDiv href') as you attempted earlier, that is not a valid selector. You can use jQuery's data() method to read the value of data-href.
Was This Post Helpful? 0
  • +
  • -

#7 DanZman   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 24-January 18

Re: Apending to a route JS - Using Larvel

Posted 19 March 2019 - 09:54 AM

View PostCTphpnwb, on 18 March 2019 - 04:49 PM, said:

You don't seem to understand that PHP is server side and Javascript is client side. That means you either have to build the Javascript with php or use javascript to grab the link. If you give your div an id the Javascript could look like this:
var myLink = document.getElementById("myLinkedDiv");
var myURL = myLink.href; 



When I console the result using what you suggested. I get an undefined, I'm sure it has something to do with that I'm using data-href versus href.
Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: Apending to a route JS - Using Larvel

Posted 19 March 2019 - 10:32 AM

You really need to show your code if you want to keep getting help. If it's saying undefined then you probably did something wrong, so show what you did so we don't have to guess and we don't have to ask you to show your code.
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3814
  • View blog
  • Posts: 13,870
  • Joined: 08-August 08

Re: Apending to a route JS - Using Larvel

Posted 19 March 2019 - 04:01 PM

Did you give your div that id?
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Apending to a route JS - Using Larvel

Posted 20 March 2019 - 01:47 AM

View PostDanZman, on 19 March 2019 - 04:54 PM, said:

View PostCTphpnwb, on 18 March 2019 - 04:49 PM, said:

You don't seem to understand that PHP is server side and Javascript is client side. That means you either have to build the Javascript with php or use javascript to grab the link. If you give your div an id the Javascript could look like this:
var myLink = document.getElementById("myLinkedDiv");
var myURL = myLink.href; 



When I console the result using what you suggested. I get an undefined, I'm sure it has something to do with that I'm using data-href versus href.

I responded to this in post #6. A div does not have a href attribute, nor has one been added to the div.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1