php within my java script not working

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
helloise
Forum Commoner
Posts: 31
Joined: Tue Sep 21, 2010 4:20 am

php within my java script not working

Post by helloise »

Code: Select all

<script type="text/JavaScript">
   function refreshPage(s) 
   { 
       window.location.reload(); 
       if((s.options[s.selectedIndex].value) = "zed=catcher")
       {
            alert (s.selectedIndex);  [color=#FF0000]//this is showing[/color]
            <?PHP 
             //the next lines aint
                echo $form['service_code']->renderLabel();
                echo $form['service_code']->renderError();
                echo $form['service_code'];
            ?>
       }
   } 
</script>
please help?
thanks
Last edited by Benjamin on Fri Jan 14, 2011 1:21 am, edited 1 time in total.
Reason: Added [syntax=javascript] tags.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php within my java script not working

Post by AbraCadaver »

Because the PHP is being executed on the server and the resulting JavaScript is then sent to the browser. You would probably need to do something like:

Code: Select all

document.write('<?PHP echo $form['service_code']->renderLabel(); ?>');
document.write('<?PHP echo $form['service_code']->renderError(); ?>');
document.write('<?PHP echo $form['service_code']; ?>');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
helloise
Forum Commoner
Posts: 31
Joined: Tue Sep 21, 2010 4:20 am

Re: php within my java script not working

Post by helloise »

thank you it works but i displays it in a new page ! i want it to display on current page please?
thanks
Post Reply