Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 18th, 2005, 4:44 AM   #1
raikkonen
Newbie
 
Join Date: Jun 2005
Posts: 29
Rep Power: 0 raikkonen is on a distinguished road
Make Image Clickable

Hi all,

How do you make an image clickable, like a button. I need to make the image function like a button as in say, i have a button with alphabet 'a' and when i click on it, the 'a' comes out in a textbox on the same page. Do i use <img src="a.gif"> or the <input type="image" src="a.gif"> ..? What are the codes for the onClick event?

Thanks..
raikkonen is offline   Reply With Quote
Old Oct 18th, 2005, 1:19 PM   #2
bja888
Hobbyist Programmer
 
bja888's Avatar
 
Join Date: Oct 2005
Location: Central, FL
Posts: 213
Rep Power: 0 bja888 is an unknown quantity at this point
Send a message via AIM to bja888 Send a message via Yahoo to bja888
[html]
<script>
function putToBox(incvar){
document.getElementById("despout").value = incvar;
}
</script>
<body>
<a href="#" onclick="putToBox('a')"><img src="a.gif"></a><br>
<input type="text" id="despout">
</body>[/html]
bja888 is offline   Reply With Quote
Old Oct 18th, 2005, 2:22 PM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
he's how i'd do it.

<body>
		  <input type="image" src="somepic.gif" alt="Go to Google" name="go_to_google" onclick="javascript:window.location='http://www.google.com'">
</body>

one line of code :-)

note that you can also use this method to submit forms to your server.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 18th, 2005, 2:25 PM   #4
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Quote:
Originally Posted by bja888
[html]
<script>
function putToBox(incvar){
document.getElementById("despout").value = incvar;
}
</script>
<body>
<a href="#" onclick="putToBox('a')"><img src="a.gif"></a><br>
<input type="text" id="despout">
</body>[/html]
Never define an input outside of a form, it's bad coding style...
__________________

tempest is offline   Reply With Quote
Old Oct 18th, 2005, 2:40 PM   #5
bja888
Hobbyist Programmer
 
bja888's Avatar
 
Join Date: Oct 2005
Location: Central, FL
Posts: 213
Rep Power: 0 bja888 is an unknown quantity at this point
Send a message via AIM to bja888 Send a message via Yahoo to bja888
@tempest: Wow, aparently you diden't notice Pizentios did the same thing. Now ur just turning into an a$$.

Quote:
Originally Posted by Pizentios
<body>
		  <input type="image" src="somepic.gif" alt="Go to Google" name="go_to_google" onclick="javascript:window.location='http://www.google.com'">
</body>
bja888 is offline   Reply With Quote
Old Oct 18th, 2005, 3:25 PM   #6
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Quote:
@tempest: Wow, aparently you diden't notice Pizentios did the same thing. Now ur just turning into an a$$.
Apparently you didn't notice that tempest's comment was made a very short while after Pizentos's. That means he was almost certainly typing it as Pizentos's reply was being posted.

Refrain from using IM-speak and profanity towards elder members, or stop posting all together if you can't.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Oct 19th, 2005, 9:31 AM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
you can actually use the onclick attribute in a img tag as well, but your users won't get the little hand that you get when you put your mouse over a link.

Example:

<img src="somepic.gif" alt="Go to Google" onclick="javascript:window.location='http://www.google.ca'">
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 19th, 2005, 11:08 AM   #8
bja888
Hobbyist Programmer
 
bja888's Avatar
 
Join Date: Oct 2005
Location: Central, FL
Posts: 213
Rep Power: 0 bja888 is an unknown quantity at this point
Send a message via AIM to bja888 Send a message via Yahoo to bja888
It also wont be recoganised as a link. If you use the tab key to navage the site (as i sometimes do) you will never be able to get to that link. It will get the job done but only as a last resort.
bja888 is offline   Reply With Quote
Old Oct 19th, 2005, 2:15 PM   #9
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
If you want to keep up with xHTML standards and don't want to make a form just for the clicking of the link to get by validation you could also do this, giving you the "link cursor" effect.

[php]
<img src = "img.gif"
onclick = "javascript: window.location='http://www.google.com';"
onmouseover = "javascript: this.style.cursor = 'pointer';"
onmouseout = "javascript: this.style.cursor = 'default';">
[/php]
__________________

tempest is offline   Reply With Quote
Old Oct 19th, 2005, 2:22 PM   #10
bja888
Hobbyist Programmer
 
bja888's Avatar
 
Join Date: Oct 2005
Location: Central, FL
Posts: 213
Rep Power: 0 bja888 is an unknown quantity at this point
Send a message via AIM to bja888 Send a message via Yahoo to bja888
Quote:
Originally Posted by tempest
[php]
<img src = "img.gif"
onclick = "javascript: window.location='http://www.google.com';"
onmouseover = "javascript: this.style.cursor = 'pointer';"
onmouseout = "javascript: this.style.cursor = 'default';">
[/php]
You don't need the mouse out. Just make a style [html]"cursor:pointer;"[/html]
bja888 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC