//How to have two different inputs (one for mobile, one for desktop) modify the same variable?


Use :visible selector

username = $("input[name=userSearch]:visible").val();
$("input[name=userSearch]:visible") will be the visible input field.