Page 1 of 1

onclick event of a button

Posted: Fri Aug 14, 2009 4:18 pm
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.

Re: onclick event of a button

Posted: Fri Aug 14, 2009 6:36 pm
by aceconcepts
This should work for you:

Code: Select all

<input type="button" onclick="document.location='http://www.google.com/'">

Re: onclick event of a button

Posted: Fri Aug 14, 2009 8:12 pm
by skylines
hey, thanks. This worked for me.

Re: onclick event of a button

Posted: Fri Aug 14, 2009 11:36 pm
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