Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


change image on button click



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
ranosb



Joined: 15 Apr 2008
Posts: 14

PostPosted: Thu Apr 17, 2008 10:05 am    Post subject: change image on button click Reply with quote

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()">
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 563
Location: Cebu City Philippines

PostPosted: Thu Apr 17, 2008 10:26 am    Post subject: Re: change image on button click Reply with quote

When you do this:
Code:

<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 Smile

Something like this might help Wink
Code:

<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 Smile

See if it helps Wink
Back to top
View user's profile Send private message Yahoo Messenger
ranosb



Joined: 15 Apr 2008
Posts: 14

PostPosted: Thu Apr 17, 2008 10:56 am    Post subject: Re: change image on button click Reply with quote

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 11:18 am; edited 2 times in total
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 563
Location: Cebu City Philippines

PostPosted: Thu Apr 17, 2008 11:06 am    Post subject: Re: change image on button click Reply with quote

There's no document.id Wink

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

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


...this codes in your function Smile

...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 Smile

...Could you wrap in all your codes here...We'll see how we can be of help Smile
Back to top
View user's profile Send private message Yahoo Messenger
ranosb



Joined: 15 Apr 2008
Posts: 14

PostPosted: Thu Apr 17, 2008 11:14 am    Post subject: Re: change image on button click Reply with quote

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
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 563
Location: Cebu City Philippines

PostPosted: Fri Apr 18, 2008 1:25 am    Post subject: Re: change image on button click Reply with quote

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? Smile
Back to top
View user's profile Send private message Yahoo Messenger
ranosb



Joined: 15 Apr 2008
Posts: 14

PostPosted: Fri Apr 18, 2008 4:17 am    Post subject: Re: change image on button click Reply with quote

Yes thanks, using;

function ChangeImage(buttonclick) {
document.images["img" + buttonclick].src="checkbox.png"
}
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 563
Location: Cebu City Philippines

PostPosted: Fri Apr 18, 2008 4:23 am    Post subject: Re: change image on button click Reply with quote

Okay, got it now Wink

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 Smile
Code:

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...Smile

...If nothing works, could you please up all your codes..we'll try to figure this out for you Wink
Back to top
View user's profile Send private message Yahoo Messenger
ranosb



Joined: 15 Apr 2008
Posts: 14

PostPosted: Fri Apr 18, 2008 6:52 pm    Post subject: Re: change image on button click Reply with quote

Your right, that is better, keep all in the same onclick event, I will use this.
Thanks!
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 563
Location: Cebu City Philippines

PostPosted: Sat Apr 19, 2008 12:41 am    Post subject: Re: change image on button click Reply with quote

Told you.....simplicity is always the best Wink

You're welcome Smile
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap