views:

248

answers:

2

Something wrong with this line of code:

changeimage('image1', 'Photos/Customers/Test1/Dock.jpg')

What is wrong?

Edit: Javascript:

function changeImage(image_name, image_src) {
    document[image_name].src = image_src; 
}

Debug

 <img id="ctl00_Main_gridThumbnails_ctl06_tb1" src="Photos/Customers/Test1/Forest-tn.jpg" style="border-width:0px;" />
                        <input type="hidden" name="ctl00$Main$gridThumbnails$ctl06$photolink" id="ctl00_Main_gridThumbnails_ctl06_photolink" value="~/Photos/Customers/Test1/Forest.jpg" />
A: 

"Object expected" simply means that the code expected to find something (an object) but didn't find it.

With just that single line, it's hard to diagnose the problem. If the code is looking for some object, you have to track down where the object should have been created. In your case, make sure the function is defined somewhere before you try to call it.

Larsenal
+1  A: 

If your code is exactly as you have shown us, then it seems the problem lies in capitalization. You have defined changeImage with a capital 'I', but you called changeimage with a lower-case 'i'.

Try changing to:

changeImage('image1', 'Photos/Customers/Test1/Dock.jpg');

If your Javascript is in a different file, it's also possible that your link to that file is broken and is not getting loaded.

Aaron
Hold on, yeah none of my javascripts are being used/not working - I have masterpage with: <script src="/JS/Scripts/changeimage.js" type="text/javascript"></script>
tom
Use Firebug to see whether you're getting a 404 on that script.
Larsenal
All the javascripts are found, so it's not that
tom
Is it the capital 'I' problem? What do you get if you type this into your browser's location bar on your page? `javascript:alert(changeimage);`
Aaron