DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   function in php (http://www.daniweb.com/forums/thread116058.html)

queenc Mar 28th, 2008 12:17 am
function in php
 
hi,

this is a simple program it is not working...please do tell me whether my code is correct
<form>
<?php
function login()
{
 print "<script>";
print " window.location='http://www.webs.com/hi.html'";
 print "</script>"; 
}
print "<input type='button' name='butt' value='Apply Online' onClick=login() style='height :2em; width :7em; font-weight:bold; font-size:0.7em' >";
?>
</form>

sagedavis Mar 28th, 2008 12:34 am
Re: function in php
 
you can't call a php function with an onClick event.. onClick is a javascript/DHTML item.

You also don't even need any of the php opening and closing stuff.
Why cause php to print javascript and html items if you already have form tags outside of the scope of the php?

<script>
function login(){
window.location='http://www.webs.com/hi.html';
}
</script>
<form>
<input type='button' name='butt' value='Apply Online' onClick='login();' style='height :2em; width :7em; font-weight:bold; font-size:0.7em' >
</form>

Should do the trick.
Although, you really don't even need any of that stuff.
You are just wanting people to go to another page to fill out an application.
This is easily done in html
<a href="http://www.webs.com/hi.html"><img src="button.gif" /></a>

Sage

kings Mar 28th, 2008 1:52 am
Re: function in php
 
no if he is a registered user i want to redirect him to page1.php page or else page2.php...so i taught something like this will help me

sagedavis Mar 29th, 2008 3:01 am
Re: function in php
 
ok, you still can't call a php function on a javascript event, which is what your code is trying to do.

What you need to do is use your php to print out the html code but make the onclick event itself the value.

Something like this.
<?PHP
if ($user == $registered){
$onclick = "window.location='http://www.webs.com/page1.html'";
}
else {
$onclick = "window.location='http://www.webs.com/page2.html'";
}
?>
</script>
<form>
<input type='button' name='butt' value='Apply Online' onClick='
<?php echo $onclick; ?>
' style='height :2em; width :7em; font-weight:bold; font-size:0.7em' >
</form>
Obviosly you will replace user and registered with whatever you use to check users registration...


All times are GMT -4. The time now is 11:14 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC