0
<html>
<head>Testing</head>
<body>
    <?php
        if(isset($_POST['postbtn'])){
            echo "<script>alert('I am here')</script>";
            echo "<script>document.getElementById('txt_name').value='edit'</script>";
        }
    ?>

    <div id="wrap">
        <form id="data_entry" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
            <div class="rowbox">
                <input type="text" class="textbox" id="txt_name" value="">
            </div>

            <div class="btn">
                <input type="submit" id="postme" name="postbtn">
            </div>
        </form>
    </div>
</body>
</html>

I'm new to javascript and php, what I need to know is after submitting the form I can see the alert message "I am here" but I don't see the value that I am posting using the document.getElementById in the textfield for the html form. Why?

Thanks

1
  • For the javascript part: if you got these basics in order, try to dig into JQuery, it will make javascripting a lot easier. Don't forget these are the basics though. Commented Oct 19, 2013 at 7:24

1 Answer 1

2

Because the element has not loaded yet, move your script to the end of the body.

<?php
    if(isset($_POST['postbtn'])){
        echo "<script>alert('I am here')</script>";
        echo "<script>document.getElementById('txt_name').value='edit';</script>";
    }
?>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.