I am trying to open a larger picture of the original picture that is in the html document. in the html its called "bild.png" and I want to open a larger one called "big_bild.png" in a new window.
I have fetced all the images and sorted out the one I want in another function. the function I cant get to work looks like this:
function visa(){
var pic = this.src; //the original picture called from the other function
var pic1="big_"; //this is what I want to add to the original filename.
var pic2=pic1+pic;
open(pic2); }
when this runs it tries to open to files instead of adding the text "big_" to the orignal file.

I know this is really easy for those who know but I am veery new to javascript and strugeling to understand how to put it all together.
I would be very happy if someone could help me understand what I doing wrong.:?:

Recommended Answers

All 2 Replies

There is a number of ways to do this. Here are a couple:

Rule based (prepend "big_"):

function visa(){
	var imgUrlArray = this.src.split('/');
	imgUrlArray[imgUrlArray.length-1] = 'big_' + imgUrlArray[imgUrlArray.length-1];
	open(imgUrlArray.join('/'));
}

Non rule based, with large image url coded as a custom attribute of the img tag:

function visa2(img){
	open(img.getAttribute('bigSrc'));
}

Here's the HTML for use with visa2:

<img src="http://www.daniweb.com/alphaimages/misc/logo/logo.gif" bigSrc="http://www.daniweb.com/alphaimages/misc/navigation/community.gif" border="0" alt="myImage" onclick="visa2(this)">

Airshow

thank you so much, it worked, you saved my day:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.