function in php

Reply

Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

function in php

 
0
  #1
Mar 28th, 2008
hi,

this is a simple program it is not working...please do tell me whether my code is correct
  1. <form>
  2. <?php
  3. function login()
  4. {
  5. print "<script>";
  6. print " window.location='http://www.webs.com/hi.html'";
  7. print "</script>";
  8. }
  9. print "<input type='button' name='butt' value='Apply Online' onClick=login() style='height :2em; width :7em; font-weight:bold; font-size:0.7em' >";
  10. ?>
  11. </form>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: function in php

 
0
  #2
Mar 28th, 2008
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?

  1. <script>
  2. function login(){
  3. window.location='http://www.webs.com/hi.html';
  4. }
  5. </script>
  6. <form>
  7. <input type='button' name='butt' value='Apply Online' onClick='login();' style='height :2em; width :7em; font-weight:bold; font-size:0.7em' >
  8. </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
  1. <a href="http://www.webs.com/hi.html"><img src="button.gif" /></a>

Sage
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

Re: function in php

 
0
  #3
Mar 28th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: function in php

 
0
  #4
Mar 29th, 2008
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.
  1. <?PHP
  2. if ($user == $registered){
  3. $onclick = "window.location='http://www.webs.com/page1.html'";
  4. }
  5. else {
  6. $onclick = "window.location='http://www.webs.com/page2.html'";
  7. }
  8. ?>
  9. </script>
  10. <form>
  11. <input type='button' name='butt' value='Apply Online' onClick='
  12. <?php echo $onclick; ?>
  13. ' style='height :2em; width :7em; font-weight:bold; font-size:0.7em' >
  14. </form>
Obviosly you will replace user and registered with whatever you use to check users registration...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC