It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

change image on button click

change image on button click

Postby ranosb on Thu Apr 17, 2008 9:05 am

I have a button that when clicked opens a window with a new link.
I would like a image above the button.

I would like to include a function like ChangeImage() with the buttons onclick event to change the image to another(when the button is clicked)

Whats the best script for this; There are many more buttons on the page and repeated openlink function calls.

function ChangeImage() {
Change current image to this image
}

function openlink1() {
var open1 ='http://yahoo.com'
window.open(open1,'','scrollbars=yes,height=540,width=785,resizable=yes');
}


<input type=button value="Yahoo"
onclick="javascript:location.href='javascript:openlink1()'"
javascript:ChangeImage()">
ranosb
 
Posts: 14
Joined: Tue Apr 15, 2008 10:34 pm

Postby rangana on Thu Apr 17, 2008 9:26 am

When you do this:
Code: Select all
<input type=button value="Yahoo"
onclick="javascript:location.href='javascript:openlink1()'"
javascript:ChangeImage()">


...It will redirect your page to yahoo, then you'll no longer see the image,,,how about calling openlink1() function,,,and not using the location.href JS property :)

Something like this might help ;)
Code: Select all
<input type=button value="Yahoo"
onclick="changeImage();openlink1();" />


...Or you might find it useful, to use the window.open JS method on the changeImage function, anyways, get back if you're stumped :)

See if it helps ;)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby ranosb on Thu Apr 17, 2008 9:56 am

rangana,

Thanks for replys,

Your right, I didnt need the href; but for some reason it still opened a new window, but I removed it, wrong coding...

So what code can I use for the ChangeIMage() function that will change my image? Do I need to use document.id?
Last edited by ranosb on Thu Apr 17, 2008 10:18 am, edited 2 times in total.
ranosb
 
Posts: 14
Joined: Tue Apr 15, 2008 10:34 pm

Postby rangana on Thu Apr 17, 2008 10:06 am

There's no document.id ;)

...It's document.getElementById('nameofid');

...I suggest you open your page just withthe changeImage() function...just include
Code: Select all
window.open('http://www.devppl.com/forum','rangana','width=500,height=300,scrollbar=0');


...this codes in your function :)

...Actually, I see a lot of easier way to implement this one, the target attribute....,but that would mean another explanation, as I don't want you to be confused much more :)

...Could you wrap in all your codes here...We'll see how we can be of help :)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby ranosb on Thu Apr 17, 2008 10:14 am

The windows open fine as is,
I just need a changeimage() function,

I have like 10 openlink functions, each opens different windows, so I need the function to be separate
ranosb
 
Posts: 14
Joined: Tue Apr 15, 2008 10:34 pm

Postby rangana on Fri Apr 18, 2008 12:25 am

Alright....do you have the codes on your changeImage() function already?...

....And also,,,this has been leading to many branches..what was your problem BTW? :)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby ranosb on Fri Apr 18, 2008 3:17 am

Yes thanks, using;

function ChangeImage(buttonclick) {
document.images["img" + buttonclick].src="checkbox.png"
}
ranosb
 
Posts: 14
Joined: Tue Apr 15, 2008 10:34 pm

Postby rangana on Fri Apr 18, 2008 3:23 am

Okay, got it now ;)

Why not just use a openlink1 function..and change your image within the function, since you said their will be 10 functions, for 10 buttons :)
Code: Select all
function openlink1()
{
document.getElementById('imageid').src= 'checkbox.png';
var open1 ='http://yahoo.com'
window.open(open1,'','scrollbars=yes,height=540,width=785,resizable=yes');
}


...Just give your images an id...:)

...If nothing works, could you please up all your codes..we'll try to figure this out for you ;)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby ranosb on Fri Apr 18, 2008 5:52 pm

Your right, that is better, keep all in the same onclick event, I will use this.
Thanks!
ranosb
 
Posts: 14
Joined: Tue Apr 15, 2008 10:34 pm

Postby rangana on Fri Apr 18, 2008 11:41 pm

Told you.....simplicity is always the best ;)

You're welcome :)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 8 guests