I have two form fields and would like to post those values using jquery only when both have a value. I have tried this but there must be a better way. I think this way could lead to errors
$('#RFID').change(function(e){
if($(this).val() != '' && $('#STATION_ID').val() != ''){
}
});
That’s not a particularly bad approach. It could be cleaned up a little though. I would go with something like this:
Edit: The code above was assuming you wanted to post as soon as you had both values. Looking at your question again, I may have read it wrong. If you simply want to prevent the form from posting unless you have both values, you would really want this: