Author Topic: I am dumb, I need help  (Read 6229 times)

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
I am dumb, I need help
« 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.

piratePenguin

  • VIP
  • Member
  • ***
  • Posts: 3,027
  • Kudos: 775
    • http://piratepenguin.is-a-geek.com/~declan/

H_TeXMeX_H

  • Member
  • **
  • Posts: 1,988
  • Kudos: 494
    • http://draconishinobi.50webs.com/
Re: I am dumb, I need help
« Reply #2 on: 22 July 2006, 05:08 »
Don't tell me you're writing a vector graphics editor in javascript ... are you ?

xyle_one

  • VIP
  • Member
  • ***
  • Posts: 2,213
  • Kudos: 135
Re: I am dumb, I need help
« Reply #3 on: 22 July 2006, 05:36 »
Use

You dont need the javacsript in the onclick attribute as onclick is already a javascript event handler.

xyle_one

  • VIP
  • Member
  • ***
  • Posts: 2,213
  • Kudos: 135
Re: I am dumb, I need help
« Reply #4 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:
 
Code: [Select]
"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 :)

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: I am dumb, I need help
« Reply #5 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