Why is this script returning me an object?

2

I'm working with jQuery to register information in the database through Ajax and I'm not sure why this code is returning me an object type variable. The project I'm working on is being developed over a Admin Panel with the entire interface and HTML, CSS e JS ready. Here is the code:

$("#cadastra_produtos").submit(function(){

    var prod_nome       = $("#prod_nome");
    var prod_categoria  = $("#prod_categoria");
    var prod_dimens     = $("#prod_dimens");
    var prod_qtde       = $("#prod_qtde");
    var prod_valor      = $("#prod_valor");
    var prod_descr      = $("#prod_descr");

    if(prod_nome) { alert(prod_nome); } <-- isso me retorna um objeto

The only particularity of this form that I think might be generating some type error is the chosen-select plugin that is part of the system front end.

Can you help me figure out why the alert shows me an object, not the string?

    
asked by anonymous 15.11.2014 / 23:46

1 answer

6

It seems that you have noticed but for didactic purposes.

in the example:

html

<input id="prod_name" />

javascript

var nome = $("#prod_nome");

name gets an object encapsulated by jQuery to manipulate the DOM object that represents <input /> in JavaScript soon to access its value one should use .val() getting

var nome = $("#prod_nome").val();
    
16.11.2014 / 00:08