PHP inside Javascript
| From: | Samantha Savvakis | Date: | Tue, 05 Sep 2000 02:33:10 +0000 |
| Subject: | PHP inside Javascript | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-15205@lists.php.net to get a copy of this message | ||
Hi all,
I would like to put some php inside javascript. I have done this before, but
this time it's slightly different.
The problem I'm having is that the PHP is being executed, despite the fact
that it's inside a javascript function that hasn't been called yet. This is
what I want to do:
------------------------
<BODY>
<SCRIPT language="javascript">
<!--
function NextPage()
{
<?php
if ($username == "")
{
$error = "You must enter a username";
}
else if ($address == "")
{
$error = "You must enter an address";
}
else
{
?>
document.frmDetails.submit();
<?php
}
?>
}
//-->
</SCRIPT>
<FORM name=frmDetails>
<INPUT type=submit name=btnNext id=btnNext value="Next>>"
onclick="NextPage()">
</FORM>
</BODY>
------------------------------
No matter what I do, the php is being executed and $error always has a
value. Is there a way I can do PHP validation inside the javascript function
and it not be executed?
Thanks,
Sam