ramunas Posted September 1, 2011 Share Posted September 1, 2011 I have this code below and i can't fidure it out, how to make change a pictures, only change it the one at javascript, but nothing hapen with combobox. is anybody can help. Thank you<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/xml; Charset=utf-8" /><title>Logos.html</title><script language ="javascript">function changeSrc(myImage,logo){document.getElementById(myImage).src=(this is the picture from location at title logos.html, if i put a picture here it will change onChange script, but it can't pickup from the select?)}</script></head><body><table border="0" cellspacing="3" cellpadding="3"><tr><td>Logos: <select name="logo" onChange="changeSrc('myImage','logo',value)"> <option value="usalogo">usalogo</option> <option value="jura">Jura</option> <option value="lthockey">LT Hockey</option> </select></td><td><img src=("this picture also located at logos.html and it shows right a way when i opent the html page") id="myImage"></td></tr></table></body></html> Link to comment Share on other sites More sharing options...
JamesB Posted September 1, 2011 Share Posted September 1, 2011 try changing: <select name="logo" onChange="changeSrc('myImage','logo',value)"> to: <select name="logo" onChange="changeSrc('myImage',this.options[this.selectedIndex].value)"> and the changeSrc function to: function changeSrc(myImage,url){document.getElementById(myImage).src=url;} this should make it so when a user selects for example the "Jura" option, the image url will be set to "jura".you probably need to add the file extension to the <option> values. (eg. .jpg/.png) etchttp://www.w3schools.com/jsref/dom_obj_select.asp Link to comment Share on other sites More sharing options...
ramunas Posted September 1, 2011 Author Share Posted September 1, 2011 try changing:<select name="logo" onChange="changeSrc('myImage','logo',value)"> to: <select name="logo" onChange="changeSrc('myImage',this.options[this.selectedIndex].value)"> and the changeSrc function to: function changeSrc(myImage,url){document.getElementById(myImage).src=url;} this should make it so when a user selects for example the "Jura" option, the image url will be set to "jura".you probably need to add the file extension to the <option> values. (eg. .jpg/.png) etchttp://www.w3schools.com/jsref/dom_obj_select.asp Thank you so much! but still nothing hapen, look what i did, can you see any mistakes still i do wrong?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/xml; Charset=utf-8" /><title>Logos.html</title><script language ="javascript">function changeSrc(myImage,http://localhost/web/){document.getElementById(myImage).src="http://localhost/web/";}</script></head><body><table border="0" cellspacing="3" cellpadding="3"><tr><td>Logos: <select name="Logo" onChange="changeSrc('myImage',this.option[this.selectedIndex].value)"> <option value="usalogo.jpg">usalogo</option> <option value="jura.jpg">Jura</option> <option value="lthockey.jpg">LT Hockey</option> </select></td><td><img src="http://localhost/web/redferari1.jpg" id="myImage"></td></tr></table></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 1, 2011 Share Posted September 1, 2011 Why did you do this:function changeSrc(myImage,http://localhost/web/){document.getElementById(myImage).src="http://localhost/web/";}That should be a variable, not a hard-coded value. Look at the original function. It doesn't need to be changed. Link to comment Share on other sites More sharing options...
ramunas Posted September 5, 2011 Author Share Posted September 5, 2011 Thanks to everybody! I got it fINALY HERE IS THE CODE<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/xml; Charset=utf-8" /><title>Logos.html</title><script language ="javascript">function changeSrc(test){var x=test.options[test.selectedIndex].value;document.getElementById("myImage").src = x}</script></head><body><table border="0" cellspacing="3" cellpadding="3"><tr><td>Logos: <select name="logo" onChange="changeSrc(this)"> <option value="usalogo.jpg">usalogo</option> <option value="jura.jpg">Jura</option> <option value="lthockey.jpg">LT Hockey</option> </select></td><td><img src="redferari1.jpg" id="myImage"></td></tr></table></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.