www.webdeveloper.com
Results 1 to 3 of 3

Thread: using number from div

  1. #1
    Join Date
    May 2007
    Location
    Preston, Lancashire, UK
    Posts
    55

    using number from div

    Hi guys,

    I trying to get numbers from <div>'s and use them in if() commands.

    I've got the number but the if() commands don't seem to be working.

    Here is the code I'm using:

    Code:
    window.onload = showPhoto
    
    var pNum = 1; // global num
    
    function showPhoto()
    {
    	var pMain = document.getElementById("pMain"); // Attaching the pMain variable to the pMain div
    	var photo = document.getElementById("photo"); // Attaching the photo variable to the photo div
    	var photoImage = document.getElementById("photoImage");
    	var fade = document.getElementById("fade").style.visibility = "visible";
    	
    	
    	photo.innerHTML = pMain.innerHTML; /* Putting the HTML of the pMain into the photo */
    	pMain.style.visibility = "hidden";
    	photo.style.visibility = "visible";
    	photo.style.height = (photoImage.clientHeight+55)+"px";
    	
    	var wWidth = document.documentElement.clientWidth;
    	var wHeight = document.documentElement.clientHeight;
    	
    	photo.style.left = ((wWidth - photo.clientWidth)/2)+"px";
    	photo.style.top = ((wHeight - photo.clientHeight)/2)+"px";
    	
    }
    
    function nextButton()
    {
    	var photo = document.getElementById("photo"); 
    	var photoImage = document.getElementById("photoImage");
    	var picNum = parseFloat(document.getElementById("picNum").innerHTML);
    	var totalPics = parseFloat(document.getElementById("picNum1").innerHTML);
    	
    	var imageSRC = photoImage.src;
    	
    	var imageLength = photoImage.src.length;
    	
    	var imageStart = imageSRC.substring(0, (imageLength-5));
    	var imageEnd = imageSRC.substring((imageLength-4), imageLength);
    	
    	
    	if(pic == nums)
    	{
    		pNum = 1;
    		pic = 1;
    		photoImage.src = imageStart+pNum+imageEnd;
    	}
    	if(pic != nums)
    	{
    		pic = pNum;
    		pNum++;
    		photoImage.src = imageStart+pNum+imageEnd;
    	}
    	
    	photo.style.height = (photoImage.clientHeight+55)+"px";
    	document.getElementById("picNum").innerHTML = pNum;
    }
    
    function prevButton()
    {
    	var photo = document.getElementById("photo");
    	var photoImage = document.getElementById("photoImage");
    	var picNum = document.getElementById("picNum").innerHTML;
    	var totalPics = document.getElementById("picNum1").innerHTML;
    	var pic = document.getElementById("pic").value;
    	var nums = document.getElementById("nums").value;
    	
    	
    	var imageSRC = photoImage.src;
    	
    	var imageLength = photoImage.src.length;
    	
    	var imageStart = imageSRC.substring(0, (imageLength-5));
    	var imageEnd = imageSRC.substring((imageLength-4), imageLength);
    	
    	
    	if(pic == 1)
    	{
    		pNum = nums;
    		pic = nums;
    		photoImage.src = imageStart+pNum+imageEnd;
    		
    	}
    	if(pic != 1)
    	{
    		pic = pNum;
    		pNum--;
    		photoImage.src = imageStart+pNum+imageEnd;
    	}
    	
    	photo.style.height = (photoImage.clientHeight+55)+"px";
    	document.getElementById("picNum").innerHTML = pNum;
    }
    Thanks for your help,

    tecmeister.

  2. #2
    Join Date
    May 2007
    Location
    Preston, Lancashire, UK
    Posts
    55
    Sorry guys. I know what the problems was. it was me just being a noob.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    At a first glance:
    value returns strings not numbers. And in one of your functions you used for a comparison a variable not defined for that scope.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles