Please help me... not able to figure out what is wrong with this code!

<?php
if($_POST == "submitted")
{
echo '
<script type="text/javascript">
// Used them both and to my horror, none of them work!!!
document.BPC.postback.innerHTML = "postback";
document.getElementById("postback").innerHTML = "postback";
</script>
';
}
?>


<html>
<head>
<title> Help me! </title>
</head>
<body>
<form name="BPC" action="<?php echo $_SERVER; ?>" method="POST">
<input type="hidden" name="form_action" value="submitted">
<input type="submit" name="Submit" value="Enter">


<div id="postback" name="postback">
<font color="red"> No Post Back </font>
</div>
</form>
</body>
</html>

echo $_post['form_action']; and make sure the 'submitted' value is what you expect
$post is set to the form value, and the value is 'submit' 'Enter'(button label)
I dunno
could be something simple

If your problem is with the JavaScript not changing the text to "postback", there are several things that could be affecting this:
1) Your JS code is outside the <html> and </html> tags. It should be within these tags.
2) Your JS code appears before the actual #postback div. It should appear after it, I think, since if you put it before, the div isn't actually there when the JS gets executed.

Why use JavaScript at all?
You can do essentially the same with PHP much more easily:

<div id="postback">
<p style="color: red;"> 
<?php
   if($_POST['form_action'] == "submitted")
      echo "postback";
   else 
      echo "No Post Back";
?>
</p>
</div>

Alternatively, you can write it in shorthand as such:

<div id="postback">
<p style="color: red;"> 
<?php
   ($_POST['form_action'] == "submitted") ? echo "postback" : echo "No Post Back";
?>
</p>
</div>

Point of interest: The <font> tag is deprecated -- you shouldn't use it anymore. Use <p> instead for regular paragraphs, and use inline CSS styling to add the color. Also, the <div> tag doesn't need a name attribute.

Hey, thanks guys for the replies. Will try to implement the same and close this thread soon :)
(must accept that the replies indeed were of great help!) :)

Thank you all for the replies. They really helped me out solve my problem.

This thread is closed.

--
Cheers!
Aditya

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.