#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it,like prefix in forum


    Hi guys

    i have comment form code (in black colour) below, user type the comment in TEXTAREA, and click the Submit button

    i want to add DROP DOWN LIST BOX before it, that user can choose, and add that DROP DOWN value with the text in TEXTAREA into database, so just like prefix in forum

    i already tried below code (in red), but still not working, please help guys what is the right code




    <div>
    <script language="javascript" type="text/javascript">

    $(document).ready(function(){

    $("#form_submit").click(function() {
    document.getElementById("form_submit").disabled = true;
    checkcomment = trim(document.comment_form.message.value);

    if (checkcomment.length > 0) {
    var msgPrefix = document.forms["comment_form"].elements["message_prefix"].options[document.forms["comment_form"].elements["message_prefix"].selectedIndex].value;
    value = "["+msgPrefix+"] "+value;

    comment_submit();
    }
    else {
    alert("Please type some text");
    }
    document.getElementById("form_submit").disabled = false;
    });

    function comment_done() { }
    function comment_submit()
    {
    $.ajax({
    type: "POST",
    url: "/targetfile.php",
    data: $("#comment_form").serialize(),
    success: function(data){
    if (data == "SUCCESS") {
    //alert("Successful");
    document.comment_form.message.value = "";
    setTimeout (CommentAjax,0);
    }
    else {
    alert("Error: "+data);
    }
    }
    });
    }

    });
    </script>

    <form id="comment_form" name="comment_form" method="post">
    <input type="hidden" name="heu" value="addreply" />
    <input type="hidden" name="muser" value="' . $this->muser . '" />
    <input type="hidden" name="modid" value="' . $this->douid . '" />
    <input type="hidden" name="tun" value="0" />


    <select name="message_prefix">
    <option value=""></option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    </select>


    <textarea name="message" rows="4" cols="20" style="width: 70%;"></textarea><br />

    <input type="button" id="form_submit" value="Submit" />
    </form></div>
  2. #2
  3. Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Location
    London, UK
    Posts
    4,004
    Rep Power
    2794
    The following makes no sense at all.
    Javascript Code:
    value = "["+msgPrefix+"] "+value;
    Have a look at this, provided with an excess of variables to show you the way.
    Javascript Code:
    var msgForm = document.forms['comment_form'];
    var msgPrefix = msgForm.elements['message_prefix'];
    var msgPrefixVal = msgPrefix.options[msgPrefix.selectedIndex].value;
    var msg = msgForm.elements['message'];
    var msgVal = msg.value;
     
    msg.value = '[' + msgPrefixVal + '] ' + msgVal;
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

IMN logo majestic logo threadwatch logo seochat tools logo