Page 1 of 1

php within my java script not working

Posted: Thu Jan 13, 2011 6:59 am
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

Re: php within my java script not working

Posted: Thu Jan 13, 2011 10:01 am
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']; ?>');

Re: php within my java script not working

Posted: Fri Jan 14, 2011 12:32 am
by helloise
thank you it works but i displays it in a new page ! i want it to display on current page please?
thanks