Error creating a variable outside the Script. with jade / pug

0

I have a variable of this type:

- var route = "/app/imagenes/"+location.href.split("/")[location.href.split("/").length - 2];

which generates the following error:

  

Can not read property 'href' of undefined

but when I put it in a script. it's fully functional

script.
   var route = "/app/imagenes/"+location.href.split("/")[location.href.split("/").length - 2];

The problem is that it is impossible for me to pass the variable to form when the variable is inside the script. since Jade/Pug forces me to pass the variables with a " - "

form(action=route method="POST" enctype="multipart/form-data" class="col-md-6 remove-float center-block big-top-space")

I need to be able to access that variable from the form action and I have not found any way with Jade/pug

script.
        var route = "/app/imagenes/"+location.href.split("/")[location.href.split("/").length - 2];
    form(action=route method="POST" enctype="multipart/form-data" class="col-md-6 remove-float center-block big-top-space")

in advance thank you very much for your help

    
asked by Michael Valdes Gonzalez 05.02.2018 в 15:50
source

1 answer

1

When you make script. you are generating a normal javascript code, everything that is tabulated inside will be between the <script></script> tags as javascript code (without the .javascript does not treat it as javascript code, but as html tags )

Then within script. you can play with the elements as you would in javascript:

form( method="POST" id="formR" enctype="multipart/form-data" class="col-md-6 remove-float center-block big-top-space")

script.
    var route = "/app/imagenes/"+location.href.split("/")[location.href.split("/").length - 2];
    document.getElementById("formR").action= route

* I have added an id to the form to make it look easier and the script below to find it.

    
answered by 05.02.2018 / 16:16
source