0

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>

Edited by happygeek: fixed formatting

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by aditya61
0

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

1

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.

0

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

0

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

This thread is closed.

--
Cheers!
Aditya

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.