-1

I tried $('#tresc_area').val() but it didn't work (don't know why). Inputs are correctly sending the information, but textarea has problem with it. 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 here is the ajax. when i enter tresc: "content" then it correctly sends "content" but when i try to enter there tresc.value which is before declared as we can see it has a problems, even if i declare there "$('#tresc_area').val()" any propositions? please help me

    <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>

tresc: tresc.value <-- it doesn't work. somebody know how to make it work? please

Michael D
  • 83
  • 2
  • 11

3 Answers3

1

Since you're using jQuery anyway, might as well take advantage of it's DOM selectors.

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

}​
Mike Robinson
  • 24,971
  • 8
  • 61
  • 83
1

Here's a simple js fiddle how to read value from your text field: example. Enter any text to textarea and hit Send button. Remember to add return false; at the end of your Check function, so form is not submitted.

Kosta
  • 1,817
  • 1
  • 16
  • 21
  • I think the problem is in your form declaration. When you click the `Send` button, function `Check` is executed but since `Send` button is declared as submit button, the form is still submitted. Since you don't have `name` attribute on your textarea, its value is not submitted. Ether add attribute `name="tresc"` to textarea tag or change send from `type="submit"` to `type="button"` and try again. – Kosta Dec 16 '12 at 22:00
0
function get_comment_chk() {
    var ChkVars = {
        additional_register_mail_chk: 'Registered Mail $3.20 per parcel \n',
        additional_insurance_chk: 'Insurance $1.50 for every $100 of merchandise. \n',
        additional_international_chk: 'Registered Mail and insurance generally starts at $25 even for large letters, plus the cost of the postage. Please ask us for a quote.  \n'
    }

    var additonal = 'Additional Option: ';
    var mytextbox = document.getElementById('confirm_comment');
    var inputs = document.getElementsByTagName("input");

    mytextbox.value = '';
    mytextbox.value = mytextbox.value.replace(additonal  + ChkVars[this.name], "");
    for(var i = 0; i < inputs.length; i++) {
        if(inputs[i].type === "checkbox") {
            inputs[i].onchange = function(){

                $('input[name*=\'additional\']:checked').each(function(){
                    mytextbox.value = mytextbox.value  + additonal  + ChkVars[this.name];
                });

                /*if(this.checked){
                    mytextbox.value = mytextbox.value  + additonal  + ChkVars[this.name];
                } else {
                    mytextbox.value = mytextbox.value.replace(additonal  + ChkVars[this.name], ""); 
                }*/
            }
        }  
    }

}
Michał Gacka
  • 2,935
  • 2
  • 29
  • 45