View Full Version : JavaScript HELP!
SupSuper
16 Aug 2006, 18:19
Ok, so I got this:
function move(i) {
// i = -1, move up; i = 1, move down
var sel = document.getElementById('list').selectedIndex;
var oldvalue = document.getElementById('list').options[sel+i].value;
var oldtext = document.getElementById('list').options[sel+i].text;
var newvalue = document.getElementById('list').options[sel].value;
var newtext = document.getElementById('list').options[sel].text;
document.getElementById('list').options[sel+i] = new Option(newtext, newvalue, false, false);
document.getElementById('list').options[sel] = new Option(oldtext, oldvalue, false, false);
document.getElementById('list').selectedIndex = sel+i;
}
function photo() {
var sel = document.getElementById('list').selectedIndex;
var phot = document.getElementById('list').options[sel].text;
document.getElementById('photo').src="../thumb.php?photo=../photos/"+phot;
}
function send() {
var str = "";
for(var i=0; i<=document.getElementById('list').options.length; i++) {
str = str + String(document.getElementById('list').options[i].value) + ",";
}
document.getElementById('test').value=str;
}
The first function is used to move items up/down on a listbox. That works.
The second function displays the selected listbox item's image in a <img> tag. That doesn't work.
The third function takes all the IDs of the listbox items and puts them in one big string. That also doesn't work.
WRYYYYYYYYYYYYYYYYYYY?!?
MrBunsy
16 Aug 2006, 18:23
hmm, for
function photo() {
var sel = document.getElementById('list').selectedIndex;
var phot = document.getElementById('list').options[sel].text;
document.getElementById('photo').src="../thumb.php?photo=../photos/"+phot;
could you try:
var eval1 = eval("../thumb.php?photo=../photos/"+phot);
document.getElementById('photo').src=eval1
Might make a difference. Otherwise, could you pop the whole page up somewhere? trying to get my head around my own annoted scripts can be tricky enough, let alone half a script which does somehting I don't entirely get.
SupSuper
16 Aug 2006, 18:47
Nope, same deal. The photo is on the listbox's onchage event, if you're curious.
This is what I get on Opera's error console:
Event thread: change
Error:
name: TypeError
message: Statement on line 1: The Object does not implement [[Call]]
Backtrace:
Line 1 of script
photo();
At unknown location
[statement source code not available]
And for the last function:
Event thread: click
Error:
name: TypeError
message: Statement on line 22: Could not convert undefined or null to object
Backtrace:
Line 22 of inline#1 script in photos_reorder.php?id=1
str = str + String((document.getElementById("list")).options[i].value) + ",";
Line 1 of script
send();
At unknown location
[statement source code not available]
Pigbuster
16 Aug 2006, 19:42
document.getElementById('photo').src="../thumb.php?photo=../photos/"+phot;
Would you by chance need some more quotes at the end of that?
document.getElementById('photo').src="../thumb.php?photo=../photos/"+phot";
I'm just totally guessing, here. AS is similar to other languages, but I don't really mess around with documents/var and all that dilly-o.
SupSuper
16 Aug 2006, 19:45
Why would I need another quote? There's already two, and phot is a variable.
MrBunsy
16 Aug 2006, 19:46
ah yes,
document.getElementById('photo').src=" '../thumb.php?photo=../photos/'+phot";
might work? I'm guessing a bit here, but that's what I do with javascript, try every combinbation I can thikn of, and if it doens't work, sleep on it and normally i've thought up something next morning.
SupSuper
16 Aug 2006, 20:01
Sadly I've already slept on it. That's why I only posted this today. :p
Anyways, I figured out what was wrong with the photo() function. Apparently, having both a function called photo() and an object called "photo" causes a conflict of interests. I just renamed the function and it works. :)
Now, who's up for solving the mystery of the last function?
Pigbuster
16 Aug 2006, 21:31
Oops. I didn't see that other quote. Silly me.
AndrewTaylor
16 Aug 2006, 21:37
Why are you using i<= instead of i< in the for loop? Surely if i is equal to the number of elements in the array it'll be out of range?
MrBunsy
16 Aug 2006, 21:46
Sadly I've already slept on it. That's why I only posted this today. :p
Anyways, I figured out what was wrong with the photo() function. Apparently, having both a function called photo() and an object called "photo" causes a conflict of interests. I just renamed the function and it works. :)
Now, who's up for solving the mystery of the last function?
*smacks head* If I could count how many times I've done that. I think Andrew might have cracked the last one though.
SupSuper
16 Aug 2006, 22:45
Why are you using i<= instead of i< in the for loop? Surely if i is equal to the number of elements in the array it'll be out of range?D'oh! *smacks head*
Leave it to me to forget such a basic thing. Thanks, that fixed it. :)
Pigbuster
17 Aug 2006, 07:11
Well, then.
...
Anything else to do in this thread, then?
MrBunsy
17 Aug 2006, 12:49
Funnily enough I've run across a really odd problem.
function Hamster(x,y,c)
{
this.x = x
this.y = y
this.c = c
}
var bob = new Hamster(10, 10, 0)
var screen = new Array(40, 20, 1)
alert(bob.x)
(it looks like gibberish because it more or less is, I tracked down the problems I was having to this, and tried completely re-writing it in a different page)
Works perfectly fine in IE, but doesn't do anything in firefox. however, remove the arrayfunction Hamster(x,y,c)
{
this.x = x
this.y = y
this.c = c
}
var bob = new Hamster(10, 10, 0)
//var screen = new Array(40, 20, 1)
alert(bob.x)
And it works... :confused: Anyone know what on earth is going on and how to get around it? I need to be able to use an array and the other jobbie (forgotten it's name) on the same page!
It's because you used the word "screen" as your variable name. You can't. "screen" is an internal property used for getting info about the browser's screen resolution, etc, and can not be reassigned.
MrBunsy
17 Aug 2006, 15:34
It's because you used the word "screen" as your variable name. You can't. "screen" is an internal property used for getting info about the browser's screen resolution, etc, and can not be reassigned.
I even re-named everything else except screen, gah. Anyway, thanks for spotting that! I can get it working now.
SupSuper
17 Aug 2006, 17:22
That's one good thing about syntax coloring, you immediatly spot when you use a reserved word for a variable. :)
MrBunsy
17 Aug 2006, 19:55
That's one good thing about syntax coloring, you immediatly spot when you use a reserved word for a variable. :)
That's partly why it took me so long though, I use html-kit, which does that. Or at least so I thought, it actually does that for almost everything except, it seems, 'screen' :(.
Don't suppose you could recommend a better programme?
SupSuper
17 Aug 2006, 23:59
I use Macromedia Dreamweaver (http://www.macromedia.com/dreamweaver) for all my webdesigning needs.
Plutonic
18 Aug 2006, 00:16
yup, dreamweaver is great, just stay away from anything but the text editor part :p
AndrewTaylor
18 Aug 2006, 00:48
I use Macromedia Dreamweaver (http://www.macromedia.com/dreamweaver) for all my webdesigning needs.
Me too. And yes, the WYSIWYG view is never seen.
I find Dreamweaver too bulky and resource hogging. Personally, i use UltraEdit (http://www.ultraedit.com/). It's fairly lightweight, and has syntax highlighting etc. In fact, i use it for most languages, not just HTML, as you can configure it to run compilers. It has a cool "Find and Replace in entire directory" feature as well.
MrBunsy
18 Aug 2006, 09:30
Hmm, I used to use dreamweaver ages ago, got it from somewhere for free. I could always give that another go sometime.
Unfortunatly, as much as ultra-edit looks nice, I can't get hold of that for free (legally) so I'd rather stick with something else.
Thanks for the links though.
I use Notepad because I'm stubborn.
SomePerson
19 Aug 2006, 01:11
Yeah! Notepad!
*high-five*
Hehehehehehe. Watch CyberShadow's FAR demo, and you'll see a great IDE! ;D Wow, FAR owns sooo much more than I knew.
vBulletin® v3.8.6, Copyright ©2000-2013, Jelsoft Enterprises Ltd.