SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using classic asp and jscript for arrays and pulling data from sql for rollovers.

    I wasn't sure where to post this, but the main topic is classic asp.

    I was wondering if there was a way to use classic asp in conjunction with a jscript for arrays. I'm pulling data from sql using classic asp. I want to create script array from data(image1,image2...) and perform on mouse out and on mouse over using this asp code. Is this possible? So far I have :

    <%

    if rs("image2") <> "" then

    %>

    <script type="text/javascript">
    var imgArray = new Array(
    imgArray[0] = <%= rs("image2").Value %>;
    imgArray[1] = <%= rs("image3").Value %>;
    imgArray[2] = <%= rs("image4").Value%>;
    imgArray[3] = <%= rs("image5").Value %>;
    imgArray[4] = <%= rs("image6").Value %>;
    imgArray[5] = <%= rs("image7").Value%>;
    imgArray[6] = <%= rs("image8").Value%>;
    imgArray[7] = <%= rs("image9").Value%>;
    imgArray[8] = <%= rs("image10").Value%>;
    );

    var imgPath = "media/images/";

    function swapImage(imgID) {
    var theImage = document.getElementById('theImage');
    var newImg;
    newImg = imgArray[imgID];
    theImage.src = imgPath + newImg;
    }

    function preloadImages() {
    for(var i = 0; i < imgArray.length; i++) {
    var tmpImg = new Image;
    tmpImg.src = imgPath + imgArray[i];
    }
    }
    </script>

    <% end if%>

    Is this the correct way in setting up an array using asp and jscript?

    <img src="media/images/<%= rs("image9")%>" onmouseover="swapImage(7)" onmouseout="swapImage(0)"></td>

    All the rs("image") Images show up but no roll over.
    Thanks in advance
    Steve

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code ASP:
    <%
    if rs("image2") <> "" then
    %>
     
    <script type="text/javascript">
    var imgArray = new Array(
    <%
    For i = 2 to 10
    %>
    imgArray[<%=(i-2)%>] = "<%=rs("image" & i)%>";
    <%
    Next
    %>
    );
     
    var imgPath = "media/images/";
     
    function swapImage(imgID) {
    var theImage = document.getElementById('theImage');
    var newImg;
    newImg = imgArray[imgID];
    theImage.src = imgPath + newImg;
    }
     
    function preloadImages() {
      for(var i = 0; i < imgArray.length; i++) {
        var tmpImg = new Image;
        tmpImg.src = imgPath + imgArray[i];
      }
    }
    </script>
     
    <%
    end if
    %>

    The key part is to check the HTML of the rendered page (View | Source) to make sure the JS syntax is correct.
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •