Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-22-2010, 05:12 AM   PM User | #1
bfly03
New Coder

 
Join Date: Mar 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
bfly03 is an unknown quantity at this point
dropdown change a btn?

i am trying to get my drop down menu to change a button's link... is this possible?

cheers,
bfly03 is offline   Reply With Quote
Old 07-22-2010, 01:33 PM   PM User | #2
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
i am trying to get my drop down menu to change a button's link... is this possible?

cheers,
It should be. Do you have some code for us to look at?
__________________
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
Old 07-22-2010, 02:42 PM   PM User | #3
bfly03
New Coder

 
Join Date: Mar 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
bfly03 is an unknown quantity at this point
Quote:
Originally Posted by Rowsdower! View Post
It should be. Do you have some code for us to look at?
I think I am looking for something like a onChange event but I am not sure.
I am still very new to js.... and i have not built anything as of yet i wanted to see how to do it first.

any ideas?
bfly03 is offline   Reply With Quote
Old 07-22-2010, 04:27 PM   PM User | #4
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
I think I am looking for something like a onChange event but I am not sure.
I am still very new to js.... and i have not built anything as of yet i wanted to see how to do it first.

any ideas?
Yes, "onchange" is your event of choice for this. Take a look here to get some ideas:
http://www.javascriptkit.com/jsref/select.shtml#aform

You would just need to alter the script so that instead of opening a website in a new window it will just get an element by id and change it's href or action attriubte. Try it for yourself and if you get stuck post back with the code you used and the specific problem you are having. I'll be happy to help you learn.
__________________
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
Old 07-22-2010, 07:50 PM   PM User | #5
bfly03
New Coder

 
Join Date: Mar 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
bfly03 is an unknown quantity at this point
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";
    }
    
}
bfly03 is offline   Reply With Quote
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
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:38 PM.


Advertisement
Log in to turn off these ads.