SomeDude SomeDude - 8 months ago 50
jQuery Question

input value not getting read by jQuery

I've spent days looking for an error in PHP only to discover my jQuery was never passing the correct value via AJAX in the first place. I was 100% sure this worked and have tested in the past:


var barcode = null;
if ($("#barcode").length)
{ var $barcode = $("#barcode").val(); console.log("barcode"); }


<div class="col-lg-10">
<input type="text" class="form-control" id="barcode" placeholder="Barcode">

Why does barcode still equal null when there are values in the barcode input?


Because the variable you are assigning a value to is


and you alert


Like in real life $ matters