Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.getElementById doesn't work with textarea

I have been trying for so long and I can't find the problem.

The getelementbyId takes correctly data from two first ids: 'odbiorca' and 'temat' and it correctly add it to database, but it doesn't happen in the case of textarea 'tresc'.

Can somebody please help me?

<form method="post">
    <input class="input" type="text" name="do_kogo" id="odbiorca" size="25" value="<?php print $odbiorca; ?>" />
    <input class="input" id="temat" type="text" name="temat" size="25" value="<?php print $temat; ?>"/>
    <textarea id="tresc_area" cols="45" rows="10" ></textarea>
    <input onclick="Check()" id="send_submit" type="submit" value="Send" />
</form>​

and heres the ajax for it

<script type="text/javascript">

var odbiorca = document.getElementById("odbiorca");
var temat = document.getElementById("temat");
var tresc = document.getElementById("tresc_area");

function Check() {
    $.ajax({
        type: "POST",
        url: "send_prv_msg.php",
        data: {
            do_kogo: odbiorca.value,
            temat: temat.value,
            tresc: tresc.value
        },
        success: function(odp) {
            $("p#error_box").html(odp);
        }
    });

}​

</script>

Does anybody know why odbiorca.value and temat.value works correct, but tresc.value doesn't?

like image 474
Michael D Avatar asked Jan 21 '26 12:01

Michael D


1 Answers

you should change your code like below. The

<script type="text/javascript">

function Check() {
    /*get the value in each click*/
    var odbiorca = document.getElementById("odbiorca");
    var temat = document.getElementById("temat");
    var tresc = document.getElementById("tresc_area");
    $.ajax({
        type: "POST",
        url: "send_prv_msg.php",
        data: {
            do_kogo: odbiorca.value,
            temat: temat.value,
            tresc: tresc.value
        },
        success: function(odp) {
            $("p#error_box").html(odp);
        }
    });

}​

</script>
like image 126
Tony Woo Avatar answered Jan 24 '26 00:01

Tony Woo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!