?
Solved

onChange not sending the desired value, minor debug assistance needed

Posted on 2008-11-10
6
Medium Priority
?
723 Views
Last Modified: 2013-11-05
Attached code snippet.

When the user changes the value of the <SELECT> element, I want to send the VALUE of the selected element (i.e., https://secure.url.com, etc.) to the changeimage function, which in turn displays a different image in the <IMG> tag identified by "imagea".

The way I have it now, it is returning something like "[object%20HTMLSelectElement]" to the function instead.

I'm sure there is just something that isn't quite right that is very easy to fix. Thanks!
<SELECT NAME="lm_image" SIZE="36" ONCHANGE="changeimage(this)">
	<OPTION VALUE="https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C">159P.jpg
	<OPTION VALUE="https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C159P%2Ejpg">4-drawer-dresser_lg.jpg
	<OPTION VALUE="https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C159P%2Ejpg">cchaydencan.jpg
	<OPTION VALUE="https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C159P%2Ejpg">kr155.jpg
	<OPTION VALUE="https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C159P%2Ejpg">NApinktoilesw_th.jpg
	<OPTION VALUE="https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C159P%2Ejpg">widgeonfleececoat.jpg</SELECT>
 
<SCRIPT LANGUAGE="JavaScript"><!-- Hide from old browsers
	if (document.images) {
 
	var imageaoff = new Image()
	imageaoff.src = "https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C159P%2Ejpg"
	}
 
	function changeimage(newUrl) {
	if (document.images)
	document.imagea.src = eval(newUrl)
	}
// Stop hiding from old browsers -->
</SCRIPT>
 
<IMG NAME="imagea" SRC="https://secure.url.com/livemerchant/images_thumb.asp?filename=D%3A%5Ctathamstamps%2Ecom%5Clm%5Fscans%5C159P%2Ejpg" BORDER="0">

Open in new window

0
Comment
Question by:bbdesign
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:und3ath
ID: 22924088
newUrl is the whole object!!! You have to use newUrl.value
document.imagea.src = eval(newUrl.value);

Open in new window

0
 

Author Comment

by:bbdesign
ID: 22924145
OK, rightly so. I tried that, but now when I change the menu nothing happens at all. Before it would change to a "broken image" icon, now nothing. Is there something else in there that isn't quite right?
0
 

Author Comment

by:bbdesign
ID: 22924224
I'm tracking what is being passed to the function, and its saying "undefined". So I'm wondering if where it says ONCHANGE="changeimage(this)" is the problem? Will that properly pass the value of the <OPTION> element that is selected?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Accepted Solution

by:
und3ath earned 2000 total points
ID: 22924260
my modification
<SELECT NAME="lm_image" SIZE="36" ONCHANGE="changeimage(this)">
        <OPTION VALUE="1.gif">159P.jpg
        <OPTION VALUE="2.gif">4-drawer-dresser_lg.jpg
        <OPTION VALUE="3">cchaydencan.jpg
        <OPTION VALUE="4">kr155.jpg
        <OPTION VALUE="5">NApinktoilesw_th.jpg
        <OPTION VALUE="6">widgeonfleececoat.jpg</SELECT>
 
<SCRIPT LANGUAGE="JavaScript">
        if (document.images) {
 
        var imageaoff = new Image();
        imageaoff.src = "";
        }
 
        function changeimage(newUrl) {
        if (document.images)
        document.imagea.src = newUrl.value;
        }
 
</SCRIPT>
 
<IMG NAME="imagea" SRC="" BORDER="0">

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22924382
on what you posted originally, try:
        function changeimage(newUrl) {
        	if (document.images)
        		document.images.imagea.src = newUrl.value
        }

Open in new window

0
 

Author Comment

by:bbdesign
ID: 22924445
I believe its working now, thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question