Page 1 of 1

image on button

Posted: Mon Dec 07, 2009 1:23 am
by myasirm
hi guys
i want to to display image on buttons in my web so how can i do this in html

Re: image on button

Posted: Mon Dec 07, 2009 1:37 am
by cpetercarter

Re: image on button

Posted: Mon Dec 07, 2009 4:27 am
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" />

Re: image on button

Posted: Tue Dec 08, 2009 12:48 am
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

Re: image on button

Posted: Tue Dec 08, 2009 1:43 am
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.

Re: image on button

Posted: Tue Dec 08, 2009 1:45 am
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>

Re: image on button

Posted: Tue Dec 08, 2009 10:07 am
by pickle
Just use the <button> tag. Much simpler than mucking around with Javascript.