Link to home
Start Free TrialLog in
Avatar of steverguy
steverguy

asked on

Javascript Functions

I'm trying to execute a javascript function that requires a set number of values.  The values need to be pulled from a database using asp.

The function I'm using is basically a photo gallery.  It changes the image as well as various text fields located around the image using element ids.  I have 2 buttons on my site that I want to use to cycle through the images.

The link for the buttons are:
    <a href="#_self" onclick="MoveNext(0,x)"> and <a href="#_self" onclick="MoveNext(1,x)">
   
     x is suppose to be the number of the current picture

Here's the javascript code I have:

<script language="Javascript">
function MoveNext(Direct,curPic)
{
      if (Direct == 0){
            x = curPic - 1
      }
      if (Direct == 0){
            x = curPic + 1
      }
      // eventually i want to fill these arrays from a database
                pictureA = new Array("build.jpg","buy.jpg","rent.jpg")
      highschoolA = new Array("Kent Co.","Grand Traverse","Kalkaska")
      yearbuiltA = new Array("1999","2000","2006")
      archiA = new Array("Ranch","Duplex","Two Story")
      sqfeetA = new Array("1000","2000","3000")
      priceA = new Array("250,000","120,000","75,000")
      bathA = new Array("2","3","4")
      bedA = new Array("1","7","5")
      thelinkA = new Array("images/icons/build.jpg","images/icons/buy.jpg","images/icons/rent.jpg")
      
      function Gallery(pictureName,imageFile,highschool,yearbuilt,archi,sqfeet,price,bath,bed,thelink)
            {
                  if (document.all)
                  {
                        document.getElementById(pictureName).style.filter="blendTrans(duration=1)";
                        document.getElementById(pictureName).filters.blendTrans.Apply();
                  }
                        document.getElementById(pictureName).src = imageFile;
                  if (document.all)
                  {
                        document.getElementById(pictureName).filters.blendTrans.Play();
                  }
                        document.getElementById("school").innerHTML=highschool;
                        document.getElementById("yearbuilt").innerHTML=yearbuilt;
                        document.getElementById("archi").innerHTML=archi;
                        document.getElementById("sqfeet").innerHTML=sqfeet;
                        document.getElementById("price").innerHTML=price;
                        document.getElementById("bed").innerHTML=bed;
                        document.getElementById("bath").innerHTML=bath;
                        document.getElementById("thelink").innerHTML=thelink;
                  }
      
      Gallery('pictureName',imageFileA(x),highschoolA(x),yearbuiltA(x),archiA(x),sqfeetA(x),priceA(x),bathA(x),bedA(x),thelinkA(x))
Return(x);
}
</script>

I'm new to javascript, so I wrote the MoveNext function the way it made sense to me - which is obviosuly wrong.  No laughing please :)  - the Gallery function was written by someone else, and it works fine by itsself.

If anyone can point me in the right direction here, I'd appreciate it!
Avatar of Preece
Preece
Flag of United States of America image

First thing that I see is that it appears as though you've defined a function within a function.  Functions should be defined separately:

<script language="JavaScript" type="text/javascript">
<!--
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function MoveNext(Direct,curPic)  {
  if (Direct == 0){
    x = curPic - 1
  }
  if (Direct == 0){
    x = curPic + 1
  }
  // eventually i want to fill these arrays from a database
  pictureA = new Array("build.jpg","buy.jpg","rent.jpg")
  highschoolA = new Array("Kent Co.","Grand Traverse","Kalkaska")
  yearbuiltA = new Array("1999","2000","2006")
  archiA = new Array("Ranch","Duplex","Two Story")
  sqfeetA = new Array("1000","2000","3000")
  priceA = new Array("250,000","120,000","75,000")
  bathA = new Array("2","3","4")
  bedA = new Array("1","7","5")
  thelinkA = new Array("images/icons/build.jpg","images/icons/buy.jpg","images/icons/rent.jpg")
 
  Gallery('pictureName',imageFileA(x),highschoolA(x),yearbuiltA(x),archiA(x),sqfeetA(x),priceA(x),bathA(x),bedA(x),thelinkA(x))
  Return(x);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function Gallery(pictureName,imageFile,highschool,yearbuilt,archi,sqfeet,price,bath,bed,thelink)  {
  if (document.all)
  {
    document.getElementById(pictureName).style.filter="blendTrans(duration=1)";
    document.getElementById(pictureName).filters.blendTrans.Apply();
  }
  document.getElementById(pictureName).src = imageFile;
  if (document.all)
  {
    document.getElementById(pictureName).filters.blendTrans.Play();
  }
    document.getElementById("school").innerHTML=highschool;
    document.getElementById("yearbuilt").innerHTML=yearbuilt;
    document.getElementById("archi").innerHTML=archi;
    document.getElementById("sqfeet").innerHTML=sqfeet;
    document.getElementById("price").innerHTML=price;
    document.getElementById("bed").innerHTML=bed;
    document.getElementById("bath").innerHTML=bath;
    document.getElementById("thelink").innerHTML=thelink;
  }
}

//-->
</script>

Preece
ASKER CERTIFIED SOLUTION
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steverguy
steverguy

ASKER

Thanks for your help.  I'll really have to look it over, as some of it is over my head.  But i feel much further now than I did when i ran into the problem yesterday.  Thanks for your help!