Member Avatar

My problem is that I am trying to execute a function on button click event but it just shows not even for a sec it just flashes.

html & Javascript :

    <script type="text/javascript">
    function createLabel(){

    /*Get UserName*/
    var unString = document.createElement("label");
    unString.className = "userName";
    var uName = document.getElementById("username").innerHTML;
    unString.innerHTML = "By <a href='profile.php'>" + uName + "</a>";
    /*Get UserName*/

    /*Get PostString*/
    var postString = document.createElement("label"); 
    var postText = document.getElementById("poster").value;       
    postString.className = "postText";
    postString.innerHTML = "\n\n" + postText; = "block";
    /*Get PostString*/

    var hr = document.createElement("hr");

    var tr = document.createElement("tr");
    var td = document.createElement("td");
    td.className = "postTD";




    <div id="wrapper">

    <form id="form1" method="POST" action="">

    <textarea id="poster" name="postbox" rows="4" style="position: absolute; resize:none; margin-left:450px; margin-top:70px;" cols="70"></textarea>
    <input type="submit" onclick="createLabel();" value="Post" style="position: absolute; margin-top:160px; margin-left:990px;" id="submit" name="submit" />
    <div id="hrln1" style="position:absolute; margin-top:180px; width:1050px; margin-left:0px;"><hr /></div>

    <a href="profile.php"><label id="username" style="cursor:pointer;"><?php echo user_details('username'); ?></label></a>

    <div id="postContainer">
    <table id="postTable" cellpadding="5">          
Member Avatar

The button is causing a postback. Return false from your function to cancel the postback. Or have:

onclick="blah(); return false;"
Be a part of the DaniWeb community

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