HI EVERY BODY
CAN ANY PERSON TELL ME THAT HOW I CAN CHANGE PRODUCT IMAGE (MAY BE JPG,GIF. ) ONE BY ONE IN ASP. FOR EXAMPLE IAM DESIGNING A TEXTILE SITE. I WANT MY TEXTILE PRODUCT CHANGE ONE BY ONE IN ONE SPACE.
:cool:
HI EVERY BODY
CAN ANY PERSON TELL ME THAT HOW I CAN CHANGE PRODUCT IMAGE (MAY BE JPG,GIF. ) ONE BY ONE IN ASP. FOR EXAMPLE IAM DESIGNING A TEXTILE SITE. I WANT MY TEXTILE PRODUCT CHANGE ONE BY ONE IN ONE SPACE.
:cool:
As noted, the image swap must happen on the client (JavaScript). Classic ASP can generate the list of product image URLs (from a folder or database) and emit them into a small JavaScript array. asked for source code; below is a minimal, practical pattern that builds the list on the server and lets the browser rotate images one by one.
Server-side (Classic ASP) emits a client-side array; the browser preloads and cycles images. Place an <img> with a fixed width/height (prevents layout jump) and give it an id the script can target.
<img id="prodImage" src="/images/products/default.jpg" alt="Product" width="300" height="300" />
<script type="text/javascript">
var images = [];
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(Server.MapPath("/images/products"))
For Each file In folder.Files
ext = LCase(fso.GetExtensionName(file.Name))
If ext = "jpg" Or ext = "jpeg" Or ext = "gif" Or ext = "png" Then
Response.Write "images.push('" & Replace("/images/products/" & file.Name, "'", "\'") & "');" & vbCrLf
End If
Next
Set folder = Nothing
Set fso = Nothing
%>
var idx = 0;
function preload(){
for(var i=0;i<images.length;i++){
var p = new Image(); p.src = images[i];
}
}
function showNext(){
if(!images.length) return;
idx = (idx + 1) % images.length;
document.getElementById('prodImage').src = images[idx];
}
preload();
var timer = setInterval(showNext, 3000);
</script> Practical notes: validate image extensions and folder rights on the server; escape filenames so the JavaScript string is safe; set width/height on the <img> to avoid flicker; provide a non-JS fallback (first image or thumbnails) for accessibility; consider storing filenames in a database if images are dynamic. For debugging, check Server.MapPath paths, verify file permissions, and open the page source to confirm the emitted images array is correct.
Jump to Post— Comatose 290use javascript, give the picture a name, and then change it's .src property?
use javascript, give the picture a name, and then change it's .src property?
i know sir javascript must be use for this purpose but i want source code ;)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.