DarkScythe
12-14-2003, 06:56 PM
Hello everyone, this is my first post here.
Just stumbled onto this forum via google, looking for a javascript forum, and I hope this place is friendly ^^;
Anyway, I'm an utternewb to javascript, and have been racking my brains over this, what should be a very simple script, for over a month now. I've read over large portions of a Javascript bible and asked everyone I know, and several other forums (albeit, not specifically webdev) and everyone was baffled.
My first thing is.. is this even possible with Javascript?
Here's the background:
I am creating a blog, but to set an atmosphere for the reader, I wish to have a MIDI playing in the background appropriate to the mood of the entry.
I asked myself how to go about this, and came up with the following:
I'll start off with a Mood, and set whatever text that follows as a variable. (This is my main problem as of now)
Whatever text there will trigger one MIDI from a list and write an embed code for it into the document and play it.
It seems simple, but for some reason it will not work no matter what I try. I have stamped out all syntax errors, and have come up with this. (To keep things neat, I split up the code into the base HTML code that calls up a separate *.js code in the header)
The HTML says:
Current Mood: <span id="mood">Happy</span>
This is in the body, there is a script tag in the header that calls a JS file in.
The Javascript has this:
var mood = document.getElementById('mood')
document.write("currently set mood is " + mood +"<br><br>")
switch (mood)
{
case "Sad":
document.write("<embed src='http://www.darkscythe.com/bgm/ccs_its-my-life.mid' loop='999' autostart='true' hidden='true'>")
break
case "Happy":
document.write("<embed src='http://www.darkscythe.com/bgm/bgm18.mid' loop='999' autostart='true' hidden='true'>")
}
Hopefully this isnt too long, but where I told it to write "currently set mood is.." it will say "currently set mood is null"
I'm guessing this is a problem with the code not being able to recognize what is directly after Mood in the html, defined between the SPAN tag. Someone suggested I use the .innerHTML thing, but I have no idea how to use it...
Can anyone else take a crack at it?
Just stumbled onto this forum via google, looking for a javascript forum, and I hope this place is friendly ^^;
Anyway, I'm an utternewb to javascript, and have been racking my brains over this, what should be a very simple script, for over a month now. I've read over large portions of a Javascript bible and asked everyone I know, and several other forums (albeit, not specifically webdev) and everyone was baffled.
My first thing is.. is this even possible with Javascript?
Here's the background:
I am creating a blog, but to set an atmosphere for the reader, I wish to have a MIDI playing in the background appropriate to the mood of the entry.
I asked myself how to go about this, and came up with the following:
I'll start off with a Mood, and set whatever text that follows as a variable. (This is my main problem as of now)
Whatever text there will trigger one MIDI from a list and write an embed code for it into the document and play it.
It seems simple, but for some reason it will not work no matter what I try. I have stamped out all syntax errors, and have come up with this. (To keep things neat, I split up the code into the base HTML code that calls up a separate *.js code in the header)
The HTML says:
Current Mood: <span id="mood">Happy</span>
This is in the body, there is a script tag in the header that calls a JS file in.
The Javascript has this:
var mood = document.getElementById('mood')
document.write("currently set mood is " + mood +"<br><br>")
switch (mood)
{
case "Sad":
document.write("<embed src='http://www.darkscythe.com/bgm/ccs_its-my-life.mid' loop='999' autostart='true' hidden='true'>")
break
case "Happy":
document.write("<embed src='http://www.darkscythe.com/bgm/bgm18.mid' loop='999' autostart='true' hidden='true'>")
}
Hopefully this isnt too long, but where I told it to write "currently set mood is.." it will say "currently set mood is null"
I'm guessing this is a problem with the code not being able to recognize what is directly after Mood in the html, defined between the SPAN tag. Someone suggested I use the .innerHTML thing, but I have no idea how to use it...
Can anyone else take a crack at it?