Executing function in a listbox

Hi All,

I have a jquery function that will reset a column to 0 in a SQL table depending on the Barcode inputted by the user.

Untitled

The function executes when the Barcode is in the textbox and the user clicks ‘reset carrier’, but when the user clicks ‘add to list’ to add to the barcode to the listbox, it brings back an error when clicking ‘reset carrier’, which is one my error validations if the barcode is not 8 characters long. This is my function…

** function resetCarrier() {
var barcode = document.getElementById(“barcode”).value.toUpperCase();

	console.log(barcode);
	//document.getElementById("errorMessage").innerHTML="";
	$("#errorMessage").text("");
	document.getElementById("barcode").value="";
	
$.post("carrierResetProcedure.php",{barcode: barcode},function(data, status){
console.log("Data: '"+data+"'");
if(data=='') {
		$("#errorMessage").html('<div class="alert alert-success"><strong>'+barcode+' carrier successfully updated.</strong></div>');
	}
	else {
		$("#errorMessage").html('<div class="alert alert-danger"><strong>ERROR: '+data+'<br>No change has been made to the data.</strong></div>');
		$("#errorMessage").html("ERROR: "+data+"<br>No change has been made to the data.");
		console.log(data);
		
		//document.getElementById("errorMessage").innerHTML=data;
	}
});

}

Any help would be greatly appreciated, as I can’t figure out where i’m going wrong.

Thanks.

If your function really checks that the barcode is 8 characters long and returns an error otherwise, and you get this error, that implies that your barcode is not 8 characters long - you can check this easily with var_dump. The code you postet has nothing to do with adding something to a textbox or checking any value within PHP.

Hi Chorn, thanks for getting back. The error was in a different javascript function which I’ve got to add the item to the listbox, I had a rogue # before my declared variable. All works fine now. Thanks.

Sponsor our Newsletter | Privacy Policy | Terms of Service