943,594 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2915
  • PHP RSS
Mar 28th, 2008
0

function in php

Expand Post »
hi,

this is a simple program it is not working...please do tell me whether my code is correct
PHP Syntax (Toggle Plain Text)
  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>
Similar Threads
Reputation Points: 9
Solved Threads: 4
Junior Poster
queenc is offline Offline
145 posts
since Mar 2008
Mar 28th, 2008
0

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?

PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  1. <a href="http://www.webs.com/hi.html"><img src="button.gif" /></a>

Sage
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
sagedavis is offline Offline
86 posts
since Nov 2007
Mar 28th, 2008
0

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
Reputation Points: 3
Solved Threads: 2
Junior Poster
kings is offline Offline
107 posts
since Nov 2007
Mar 29th, 2008
0

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 Syntax (Toggle Plain Text)
  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...
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
sagedavis is offline Offline
86 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: using statements in user defined functions
Next Thread in PHP Forum Timeline: Is it possible to import profile details from Myspace.com?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC