onclick event of a 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
skylines
Forum Newbie
Posts: 8
Joined: Tue Jul 28, 2009 2:45 am

onclick event of a button

Post by skylines »

Hi,

I want to call a php script in onclick event of Button in HTML. I used the following code,
<input type="submit" name="button" value="button" onclick="login.php" />

when i click the button the page is not going to login.php and in apache i am getting an error "use of undefined constant login" .

In the input tag for attribute type i tried with both. type="button" and type="submit".
Really i have no idea what is the difference between button and submit for type attribute.

Can anyone pls help me out.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: onclick event of a button

Post by aceconcepts »

This should work for you:

Code: Select all

<input type="button" onclick="document.location='http://www.google.com/'">
skylines
Forum Newbie
Posts: 8
Joined: Tue Jul 28, 2009 2:45 am

Re: onclick event of a button

Post by skylines »

hey, thanks. This worked for me.
User avatar
swhistlesoft
Forum Newbie
Posts: 9
Joined: Fri Aug 14, 2009 10:53 pm
Location: Ontario

Re: onclick event of a button

Post by swhistlesoft »

onClick is a client side event usually used with javascript. If you want a specific php script to be called using an onclick event, simply use:

Code: Select all

  1. <input type="button" onclick="document.location='http://www.yourdomain.com/login.php'">
as aceconcepts suggested. If you already understood my explanation from aceconcepts, then ignore this post :D
Post Reply