if( $( "#config" ) ) {
is always going to be true with jQuery since jQuery returns an object and objects are truthy. The check should be checking the length which will return a number and zero is false.
if ($("#config").length) {
Now when jQuery does not find an element, than val() will return undefined, so it is not finding the element.