I want to call a javascript function from php at the form submit event. and that javascript function will access the php variables, send them to a php script on another website using ajax. The following code is just a representation.
<?php
....
.....
......
if($_POST["action"]=="xyz"){
$myname = "asim";
echo "<script type='text/javascript'>submitform();</script>";
}
.....
....
...
gotoanotherpagefinally();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function submitform(){
alert("<?php echo $myname; ?>");
$.ajax({
type: 'POST',
data: {
action: 'whatever',
fileID: "<?php echo $myname; ?>",
},
url: 'http://xyz.com/API/query.php'
});
}
</script>
</head>
<body>
<form id="myform">
------
------
<input type="submit" name="submit_details">
</form>
</body>
</html>
I need to call the javascript function from php because the php variables taken by js function are only set by php itself and not the form values or something.