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

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";

<title> Help me! </title>
<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>

Edited by happygeek: fixed formatting

8 Years
Discussion Span
Last Post by aditya61

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

Edited by almostbob: n/a


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;"> 
   if($_POST['form_action'] == "submitted")
      echo "postback";
      echo "No Post Back";

Alternatively, you can write it in shorthand as such:

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

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!) :)

Edited by aditya61: n/a


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

This thread is closed.


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.