Classic ASP Carousel (Concatenation)

Asked

Viewed 82 times

1

good afternoon. I used a carousel to make a simple image gallery. I numerically named the names of the photos (1.JPG, 2.JPG, 3.JPG, ... , n.JPG) Doing "manually" (ie when I type in the entire code by inserting each image from the photo folder), it obviously works fine.

But I’d like to do this with a loop. But there’s something wrong, I think maybe it’s in the concatenation.

Follow the code, in the example below, I have 29 images.

  <div id="galeria" class="carousel slide" data-ride="carousel">   
    <div class="carousel-inner">
        <div class="carousel-item active">
          <img src="img/1.jpg" class="d-block w-100" alt="...">
        </div>
        <% For i=2 to 29 %>
        <div class="carousel-item">
          <img src="img/"<% & i & %>".jpg" class="d-block w-100" alt="...">
        </div>
        <% Next %>
    </div>
    <a class="carousel-control-prev" href="#galeria" role="button" data-slide="prev">
       <span class="carousel-control-prev-icon" aria-hidden="true"></span>
       <span class="sr-only">Anterior</span>   
    </a>   
    <a class="carousel-control-next" href="#galeria" role="button" data-slide="next">
       <span class="carousel-control-next-icon" aria-hidden="true"></span>
       <span class="sr-only">Próxima</span>   
    </a> 
</div>

Any idea?

1 answer

0


It’s wrong even that: <% & i & %>. The right thing would be: <%=i%>, that will pull the value of i of for and insert into HTML. And it’s not really a concatenation, you just want to take the value of the variable to insert into HTML code.

And you don’t need the extra quotes in the ASP code. It would be:

<img src="img/<%=i%>.jpg" class="d-block w-100" alt="...">

Quotes are only to delimit the attribute value src. The ASP code, bounded by <% %>, is an independent code processed on the server, ie the <%=i%> will be 2 to 29, resulting in HTML:

<img src="img/2.jpg" class="d-block w-100" alt="...">
<img src="img/3.jpg" class="d-block w-100" alt="...">
<img src="img/4.jpg" class="d-block w-100" alt="...">
...até o 29

The shape <%=i%> is a short form of <% Response.Write(i) %> or <% Response.Write i %>.

  • thanks!!! that’s right! I knew the problem was in <%& i & %>, I just didn’t know how to fix it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.