Dropdown change btn?

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

cheers,

hahah yeah thanks. im an idiot.

It looks as if you’ve combined the JavaScript, where you added my JavaScript try this instead:


<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> 
<script type="text/javascript">
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";
 }
}
</script> 

When you reference external JS files you need to have them in their own <script> block. Any internal scripts have to be seperate.


www.ipponsolutions.co.uk - website design in Exeter, UK.

that is exactly what i am looking for thank you.

oh i just tested it and it does not seem to be working correctly. do you know why?

http://digitalprintingservice.net/test.html

If you Google ‘html dropdown list onchange javascript’ you’ll get quite a few examples.

Here’s something I’ve just put together which might help you though:

HTML selector calls the JavaScript function dosomething()



<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>
	

JavaScript function changes the text and reference of the link depending on your selection:


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";
	}
	
}



www.ipponsolutions.co.uk - website design in Exeter, UK.

You can use the onChange() JavaScript event to edit the link as required according to the selection made.

Is this the kind of thing you’re aiming for?


www.ipponsolutions.co.uk - website design in Exeter, UK.

Do you mean your trying to change a button link using a select drop down?

rich, i looked up the change event and it seems to be what i am looking for.

i am having trouble finding anything helping me with this. do you have any ideas or knowledge of where i can go to learn this?

cheers,

i have one more question pertaining to this. if i wanted to change a separate image with each of these 4 options (as well as a link like you’ve done) is there an easy way to add that in?

Should be pretty straight forward. You just extend the example I’ve given you.

Add an image in the HTML, and in the if block of the javascript change the .src of the img, or whatever you need to alter of the image:


var img = document.getElementById("myimg");

if (.....) {

img.src = "logo.gif"

} else {
....
}


www.ipponsolutions.co.uk - website design in Exeter, UK.