I'm trying to add additional security/validation to an online form that has AJAX backend. When I try to add a filter to remove spaces (such as trying trim or replace), the functionality breaks; no error, just no action in general. What's the best way to acheive this without breaking the app? The code segment is below (including some of the latest attempts).
//var LastName = trim(document.getElementById('last_name').value)
//var Email = trim(document.getElementById('email').value)
//var City = trim(document.getElementById('city').value)
//var State = trim(document.getElementById('state').value)
//if(LastName == "" || Email == "" || City == "" || State == "" || document.getElementById('country').value == "-1" || document.getElementById('heard').value == "-1")
if(document.getElementById('last_name').value == "" || document.getElementById('email').value == "" || document.getElementById('city').value == "" || document.getElementById('state').value == "" || document.getElementById('country').value=="-1" || document.getElementById('heard').value=="-1")
//if(document.getElementById('last_name').value.replace(/^\s+|\s+$*/gm,"") == "" || document.getElementById('email').value.replace(/^\s+|\s+$*/gm,"") == "" || document.getElementById('city').value.replace(/^\s+|\s+$*/gm,"") == "" || document.getElementById('state').value.replace(/^\s+|\s+$*/gm,"") == "" || document.getElementById('country').value =="-1" || document.getElementById('heard').value =="-1")
{
alert("Please fill out required fields.")
}