View Single Post
Old 07-22-2010, 10:10 PM   PM User | #6
Rowsdower!
Senior Coder

 
Rowsdower!'s Avatar
 
Join Date: Oct 2008
Location: Some say it's everything.
Posts: 2,007
Thanks: 5
Thanked 395 Times in 388 Posts
Rowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura about
Quote:
Originally Posted by bfly03 View Post
so i got it working with the code below:
do you know how i can change an image out as well?

thanks!

Code:
<select id="myoptions" onchange="dosomething()">
    <option value="myhome">my home page</option>
    <option value="myresume">resume</option>
    <option value="myhobbies">hobbies</option>
    <option value="mydog">my dog</option>
</select>
<br /> <br />
 
<a id="mylink" href="this.html">Link on first load</a>
Code:
function dosomething() {
    var inputSelector = document.getElementById("myoptions");
    var link = document.getElementById("mylink");
    if (inputSelector.value == "myresume") {
        link.innerHTML = "My Resume";
        link.href = "resume.html";
    } else {
        link.innerHTML = "Other Things";
        link.href = "other.html";
    }
    
}
You would just need to add the image-changing lines of script into your existing function. I don't know what image you are changing or what you are changing about it, but it would look something roughly like this:
Code:
function dosomething() {
    var inputSelector = document.getElementById("myoptions");
    var link = document.getElementById("mylink");
    var myimage = document.getElementById("myimage");
    if (inputSelector.value == "myresume") {
        link.innerHTML = "My Resume";
        link.href = "resume.html";
        myimage.src="path/to/new/image/location.jpg";
    } else {
        link.innerHTML = "Other Things";
        link.href = "other.html";
        myimage.src="path/to/some/other/image/location.jpg";
    }
    
}

...
...
...

<select id="myoptions" onchange="dosomething()">
    <option value="myhome">my home page</option>
    <option value="myresume">resume</option>
    <option value="myhobbies">hobbies</option>
    <option value="mydog">my dog</option>
</select>
<br /> <br />
 
<a id="mylink" href="this.html">Link on first load</a>
<img id="myimage" alt="image description" src="path/to-image.jpg" />
__________________
The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
See Mediocrity in its Infancy
It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
Seek and you shall find... basically:
validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting
Rowsdower! is offline   Reply With Quote