M
mxliron
hi all, this code is for a picture viewer. yes, this is my first code
and my first piece of programming so i maybe simply be missing some key
notions here. the problem is: the nav onclick event buttons to flip
through the pics only work in IE and not in FF, i havnt tested anywhere
else. I have tried lots of thing such as including the code directly
after the event or in the headleft and headright functions, replacing
the event function by a simple alert(); **onclick = function () {
alert('there'); }**, or assigning the events after their elements have
been inserted into DOM,...the bastard simply doesnt recognise the
event although i assign the top nav bar events the same way. The page
can be found at http://max.nugraphic.com/ajax/aixaqua/ o know it still
looks ugly especially in IE but I havnt gotten to the design yet.
thank you so much, im losing patience
photo.js:
function createphotobox() {
var contentdiv = document.getElementById('content');
var photobox = document.createElement('div'); //pic-img tag
container
photobox.id = "photobox";
contentdiv.appendChild(photobox);
addphoto(photobox); //pic-img tag into designated container
addnav(contentdiv); //nav underneath pic conatiner above
}
function addphoto(el) { // lay pic
var pic = document.createElement('img');
pic.src = phppaths[0]; //fine array imported from php
pic.num = 0; //temporary pic index system..
pic.id = "pic";
pic.width = "480";
el.appendChild(pic);
}
function addnav(el) { //Add 2 nav items under
pic
var nav = document.createElement('div');
nav.id = "photonav";
var navleft = document.createElement('img');
var navright = document.createElement('img');
navleft.src = "images/photonav_left.gif";
navright.src = "images/photonav_right.gif";
navleft.onclick = headleft; //<<<problematic
events
navright.onclick = headright;
el.appendChild(nav);
nav.appendChild(navleft);
nav.appendChild(navright);
}
function headleft(event) {
currentpic('left');
return false;
}
function headright(event) {
currentpic('right');
return false;
}
function currentpic(direction) {
var dir = direction;
var pic = document.getElementById('pic');
var a = pic.num;
switch(dir) {
case 'right':
pic.src = phppaths[a+1];
pic.num++;
break;
case 'left':
pic.src = phppaths[a-1];
pic.num--;
break;
default:
break;
}
}
and my first piece of programming so i maybe simply be missing some key
notions here. the problem is: the nav onclick event buttons to flip
through the pics only work in IE and not in FF, i havnt tested anywhere
else. I have tried lots of thing such as including the code directly
after the event or in the headleft and headright functions, replacing
the event function by a simple alert(); **onclick = function () {
alert('there'); }**, or assigning the events after their elements have
been inserted into DOM,...the bastard simply doesnt recognise the
event although i assign the top nav bar events the same way. The page
can be found at http://max.nugraphic.com/ajax/aixaqua/ o know it still
looks ugly especially in IE but I havnt gotten to the design yet.
thank you so much, im losing patience
photo.js:
function createphotobox() {
var contentdiv = document.getElementById('content');
var photobox = document.createElement('div'); //pic-img tag
container
photobox.id = "photobox";
contentdiv.appendChild(photobox);
addphoto(photobox); //pic-img tag into designated container
addnav(contentdiv); //nav underneath pic conatiner above
}
function addphoto(el) { // lay pic
var pic = document.createElement('img');
pic.src = phppaths[0]; //fine array imported from php
pic.num = 0; //temporary pic index system..
pic.id = "pic";
pic.width = "480";
el.appendChild(pic);
}
function addnav(el) { //Add 2 nav items under
pic
var nav = document.createElement('div');
nav.id = "photonav";
var navleft = document.createElement('img');
var navright = document.createElement('img');
navleft.src = "images/photonav_left.gif";
navright.src = "images/photonav_right.gif";
navleft.onclick = headleft; //<<<problematic
events
navright.onclick = headright;
el.appendChild(nav);
nav.appendChild(navleft);
nav.appendChild(navright);
}
function headleft(event) {
currentpic('left');
return false;
}
function headright(event) {
currentpic('right');
return false;
}
function currentpic(direction) {
var dir = direction;
var pic = document.getElementById('pic');
var a = pic.num;
switch(dir) {
case 'right':
pic.src = phppaths[a+1];
pic.num++;
break;
case 'left':
pic.src = phppaths[a-1];
pic.num--;
break;
default:
break;
}
}