Problem with Javascript and textarea

0

Good evening everyone,

I have a small problem with the insertion of data via Javascript and textarea, I explain.

I have created a modal which has content to register for a training, the issue is that the user to register must necessarily put a comment, if not the javascript tells you your aunt.

The code below is made in a PHP, since it is a modal. The identifier we take from a calendar. (Hasa here there is no problem)

<textarea rows="3" id="comentario" name="comentario" class="resp" placeholder="Obligatorio introducir comentario..."></textarea></div>

<button type="button" id="singlebutton1" class="btn-u btn-u-primary" onClick="registerTraining('.$resultado_accesogen['t_vid'].','.$id.');">Inscribirse</button>';

The button sends the user's vid and the identifier of the training to which he wants to register to modal.js. Once the button is clicked, it performs the following function:

function registerTraining(vid,id) {

if (!$.trim($("#comentario").val())) { /* Si campo observaciones vacio */
    $("#comentario").addClass("error");     
} else {
    ***var disponibilidad = $('#comentario').val();***
    console.log(disponibilidad);
    $.ajax({
        type    : "GET",
        url     : "/assets/php/bookTraining.php",
        dataType: "html",
        contentType: 'application/x-www-form-urlencoded',
        beforeSend: function(jqXHR) {
            jqXHR.overrideMimeType('text/html;charset=iso-8859-1');
        },
        data    : {
            s: "book",
            vid: vid,
            id: id,
            disponibilidad : disponibilidad || ''
        },
};

The problem I see is where it is in var availability = $ ('# comment'). val (); , which does not take textarea data to define it as the availability variable.

Greetings

    
asked by Roberto Ceballos Ramirez 20.02.2017 в 22:24
source

1 answer

0

How about, I would recommend you use javascript

        var disponibilidad = document.getElementById("comentario").value 
    if( $.trim(disponibilidad) == "" ){
    disponibilidad.className += " error";

    }else {
//continuar con el envío
} 

Assuming you used an id (id="comment", as a unique identifier that should not be repeated in another tag within your php file)

Greetings!

    
answered by 20.02.2017 / 23:19
source