Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

url parameter is undefined when javascript window opens

Status
Not open for further replies.

ghafts

Technical User
Sep 7, 2008
2
US
My webpage contains thumbnail images that when moused-over, cause a larger image on the same page to change. In addition, the large image when clicked, causes a javascript window to open with an even larger image displayed based on a url parameter that is passed.

All works perfect EXCEPT that if the thumbnail image code is not utilized (no thumbnail is moused-over yet) the url parameter is passed as undefined.

In terms of the following code, the currentImage variable remains undefined unless the thumbnail portion of the javascript code is utilized.

How is this corrected?


HEAD SECTION JAVASCRIPT CODE:
Code:
var currentImage;
function showBigImage( isource,bigImage,header ) {
var theImage = document.getElementById( 'largeimage' );
theImage.src = isource;
currentImage = bigImage;
document.getElementById('photoHeader').innerHTML=header;
document.getElementById( 'largeimage' ).alt=header;
    
}

    function MM_openBrWindow(theURL,winName,features) { //v2.0
        window.open('/large_image.asp?url_image=' + currentImage,winName,features);

Thumbnail image code:
Code:
<a  href= "javascript:;" class="small_img" >
                          <td height=36 valign="middle" class="small_img" onmouseover="showBigImage( 'imagescript.asp?path=<%= images("url_img") %>&width=250','<%= images("url_img") %>','<%= images("alt_img") %>' )">
						  
						  <img src="imagescript.asp?path=<%= images("url_img") %>&amp;width=36" border="0" > </td>
                          </a>

Larger image code:
Code:
<a href="javascript:;" onclick="MM_openBrWindow('/large_image.asp?url_image=<%Response.Write(images("url_img"))%>','imagewindow','width=600,height=600')"><img src="imagescript.asp?path=<%=images("url_img")%>&width=250" name="largeimage" id"largeimage"  border="0" alt=""  ></a>
 
Since the function showBigImage never gets called until a user mouses over at least one image, the value of currentImage remains undefined.

You can initialize currentImage when it's defined, it will take care of the not defined url issue.

Greg
 
Change this line:
Code:
var currentImage ;
to:
Code:
var currentImage = "some image path you are using";
This way, the currentImage variable becomes defined.

However, this may not be the best way solve your problem. In the function MM_openBrWindow(theURL,winName,features), I would add a check to ensure that the value of currentImage has something in it before attempting to open a new window, like this:
Code:
function MM_openBrWindow(theURL,winName,features) { //v2.0
    if (currentImage && currentImage != "") {
        window.open('/large_image.asp?url_image=' + currentImage,winName,features);
    }
} // end function



Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top