I have a form which contains one text field. Now, I'm trying to echo out the contents of that input after the form was submitted. Here's my code for the same:
<script>
function postResultss()
{
document.write("<?php echo ($_POST['tweet1']); ?>");
}
</script>
<form method = "POST">
<input type = "text" name = "tweet1">
<br>
<input type = "submit" onclick = "postResultss()" />
</form>
The above code is inside a PHP file. However, nothing gets echoed out on submitting the form. The function does get called as expected, because I have tried echoing custom messages while debugging. However, nothing gets echoed out when I try to echo the value of $_POST['tweet1'], where tweet1 is the name of the input text field whose contents I'm trying to display.
What seems to be wrong here?
postResultss()is unlikely to get called - unless it hasevent.preventDefault()in the js function. Secondly, the POSTed var will NOT be available to the js function at the point of clicking the button - only AFTER the form has been submitted and event then this is the wrong approach to show theposted values.echo ("felicity");inside my JS function, the message does get displayed. Which means that the JS function is indeed being called on submitting the form.