image on button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

image on button

Post by myasirm »

hi guys
i want to to display image on buttons in my web so how can i do this in html
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: image on button

Post by cpetercarter »

hemakumarrr
Forum Newbie
Posts: 7
Joined: Mon Nov 09, 2009 12:42 am

Re: image on button

Post by hemakumarrr »

Hi,

We can use image as both button and submit.

Image as Button :
<img src="SomePath" onclick="SomeFunction()" />

Image as Submit :
<input type="image" src="SomePath" />

Hope you know whats the difference between Submit and Button.

<input type="button" onclick="SomeFunction()" />
<input type="submit" />
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

Re: image on button

Post by myasirm »

how can i use java script on image like i want to call a php page by clicking on image how i do this
waiting for ur replies
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: image on button

Post by Weiry »

myasirm wrote:how can i use java script on image like i want to call a php page by clicking on image how i do this
depends on what you want to do with your PHP page as to whether you need javascript or not

you could just set an "onClick='doFunction(varName)'" for your image tag. and tell the script to submit a form to a php page.
or just redirect to a php page based on php input "<a href='myPHPPage.php?myVar></a>"
there is a few other ways too... but it depends what your needs are.
hemakumarrr
Forum Newbie
Posts: 7
Joined: Mon Nov 09, 2009 12:42 am

Re: image on button

Post by hemakumarrr »

<script language="javascript">
function callphp()
{
document.f2.submit();
}
</script>
<form name="f2" action="sample.php">
<input type="image" src="sample.img" />
<img src="sample.img" onclick="callphp()" />

</form>
(or)
<script language="javascript">
function callphpfile()
{
window.location="sample.php";
}
</script>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: image on button

Post by pickle »

Just use the <button> tag. Much simpler than mucking around with Javascript.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply