0

Whats wrong with my code . The title is not displayed within the div banAdT :

<form action="" method="post" enctype="multipart/form-data">
    <p>
        Banner Ad Name :<br />
        <input type="text" name="bannerAdName" id="bannerAdName" />
    </p>
    <p>
        Your web page :<br />
        <input type="text" name="bannerAdWeb" id="bannerAdWeb" />
    </p>
    <p>
        Ad image :<br />
        <input type="file" name="bannerAdImage" id="bannerAdImage"/>
    </p>
    <p>
        Title :<br />
        <input type="text" name="bannerAdTitle" id="bannerAdTitle" />
    </p>
    <p>
        Description :<br />
        <textarea name="bannerAdDesc" id="bannerAdDesc" ></textarea>
    </p>
    <div id="button"><input type="button" value="VIEW" onclick="return upload()"/></div>

    <input type="hidden" value="POST" />
</form>
<div id="popupContact">
        <a id="popupContactClose">x</a>
        <div id="contactArea">
            <div id="banAdT">
                <script>document.write(document.getElementById("bannerAdTitle").value);</script> <!-- Displays nothing -->
            </div>
            <img src="" id="preview" width="120" height="120" />
        </div>
    </div>

2 Answers 2

3

That's because when the script runs, the element bannerAdTitle won't have a value. I'm not exactly sure what you're trying to do, but you probably want to attach a change event listener to the bannerAdTitle input, and write the value from there:

document.getElementById("bannerAdTitle").onchange = function() {
    document.getElementById("banAdT").innerHTML = this.value;
}

That will write the value of bannerAdTitle in the banAdT element every time the change event is fired.

Sign up to request clarification or add additional context in comments.

Comments

2

document.write is executed as the page loads, but at that point you haven't given bannerAdTitle a value - the INPUT is empty.

2 Comments

OK,so how can I display the value ?
I don't know what you're trying to do. Are you trying to update the div every time the text in the INPUT changes? In which case, you need to handle the onchange event of the INPUT.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.