Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: worker201 on 21 July 2006, 21:08

Title: I am dumb, I need help
Post by: worker201 on 21 July 2006, 21:08
Not really much chance of me ever producing a vector graphics editor - I can't even get a goddamm JavaScript to work!  Anybody want to help?

Code: [Select]
var humpics = new Array(8);
var humtext = new Array(8);
for(var i = 0; i < 8; i++) {
humpics[i] = new Image();
humpics[i].src = "images/pic0" + i + ".jpg";
  humtext[i]="text"+i;
}

function ChangeImageAndText(i)
{
  var curr;
  document.mainimg.src=humpics[i].src;

  for (j=0; j<8; j++) {
tid=humtext[j];
document.getElementById(tid).style.display="none";
  }
 
  tid=humtext[i];
  document.getElementById(tid).style.display="block";
  document.getElementById("DefaultText").style.display="none";
}
Gets called here:
Code: [Select]

The JavaScript functions are in a separate file:


Have to admit that I didn't write the script, perhaps I should have.  Browser reports "ChangeImageAndText is not defined".
Embarassing.
Title: Re: I am dumb, I need help
Post by: piratePenguin on 22 July 2006, 03:58
javascript:ChangeImageAndText(0);"> ;)

BTW I used to use onclick on
's (like you're doing) and a guy in #web on freenode (lots of helpful people in there btw) told me I shouldn't - is for linking to different [parts of] documents - I should use (or

or

, whatever suits best) instead.
Title: Re: I am dumb, I need help
Post by: H_TeXMeX_H on 22 July 2006, 05:08
Don't tell me you're writing a vector graphics editor in javascript ... are you ?
Title: Re: I am dumb, I need help
Post by: xyle_one on 22 July 2006, 05:36
Use

You dont need the javacsript in the onclick attribute as onclick is already a javascript event handler.
Title: Re: I am dumb, I need help
Post by: xyle_one on 22 July 2006, 05:38
Of course, it would be ideal to abstract your javascript into a separate behavioral layer, so you have a lean and still accessible valid markup.

Something like this:
 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



Untitled





""

Text Here






As you can see, the actually html on the page is very light. A standard unordered list with links to the images. I have included some javascript that, once it runs, hooks into the humpics element and attaches an onclick event handler to each link in the list. The function it attaches takes the href value and replaces the placeholder image. It also takes the title attribute and replaces the text in the paragraph below it. There is also a function that allows you to load many functions at load time.

Without seeing where you are implementing this I have no idea if this is even what you are looking for.

I am just bored and waiting to get my night started :)
Title: Re: I am dumb, I need help
Post by: worker201 on 23 July 2006, 03:31
Christ, ecsyle.  How am I supposed to implement that stuff when I'm reading this at the library?  Think I'm gonna stick with the