Reputation: 467
How can I call java script in php or can convert same php code in js. Please explain I am new to javascript
<?php
if(isset($_POST['Submit']))
{
$user_name = $_POST['login_name'];
if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0)
{
$msg="<span style='color:red'>The Validation code does not match!</span>";
}else{
echo "<script>FormSubmit();</script>"; //how to call here
}
}
?>
<html>
<body>
<form name="ddd" id="ddd">
<label>name:</name></label>
<input id="login_name" type="text" />
<button type="submit" onclick="return validate(); value="Submit">
</form>
<script>
function FormSubmit(){
................
................
}
</script>
</body>
</html>
Thanks in advance.
Upvotes: 0
Views: 158
Reputation: 537
The problem is FormSubmit function is definied after calling it on PHP
The solution is defining FormSubmit function before calling
Upvotes: 0
Reputation: 709
Try this.
<html>
<body>
<form name="ddd" id="ddd">
<label>name:</name></label>
<input id="login_name" type="text" />
<button type="submit" onclick="return validate(); value="Submit">
</form>
<?php
if(isset($_POST['Submit']))
{
$user_name = $_POST['login_name'];
if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0)
{
$msg="<span style='color:red'>The Validation code does not match!</span>";
}else{
echo "<script>FormSubmit();</script>"; //how to call here
}
}
?>
<script>
function FormSubmit(){
// JS logic goes here
}
</script>
</body>
</html>
Upvotes: 1