Validating <select>

Validating <select>

Hi everyone,

  Trying to validate a form and running into difficulty with select menus. Here is the script, the <select> fields are "status," "rank," "joined_month," and "joined_year." Basically, if the form is submitted without selecting an option in one of the boxes, variable "submit" is set to "no." What SHOULD be happening is if the user then makes a selection and submits the form again, "submit" should not equal "no" -- but it looks as though it is stuck on "no" regardless (although the warning next to the field disappears as it should). 

  1. $("form#add_member").submit(function() {
  2. //Hide errors
  3. $("#fname_err").hide();
  4. $("#lname_err").hide();
  5. $("#status_err").hide();
  6. $("#rank_err").hide();
  7. $("#joinedMonth_err").hide();
  8. $("#joinedYear_err").hide();
  9. //Name Variables
  10. var name_f = $("#name_f").val();
  11. var name_l = $("#name_l").val();
  12. var status = $("#status").val();
  13. var rank = $("#rank").val();
  14. var title = $("#title").val();
  15. var joined_month = $("#joined_month").val();
  16. var joined_year = $("#joined_year").val();
  17. var submit;
  18. //Validate form
  19. if (name_f == "") {
  20. $("input#name_f").focus();
  21. $("#fname_err").show("pulsate", {times:2}, 2000);
  22. submit = "no";
  23. return false;
  24. }
  25. if (name_l == "") {
  26. $("input#name_l").focus();
  27. $("#lname_err").show("pulsate", {times:2}, 2000);
  28. submit = "no";
  29. return false;
  30. }
  31. if (status == "") {
  32. $("#status").focus();
  33. $("#status_err").show("pulsate", {times:2}, 2000);
  34. submit = "no";
  35. return false;
  36. }
  37. if (rank == "") {
  38. $("#rank").focus();
  39. $("#rank_err").show("pulsate", {times:2}, 2000);
  40. submit = "no";
  41. return false;
  42. }
  43. if (joined_month == "") {
  44. $("#joined_month").focus();
  45. $("#joinedMonth_err").show("pulsate", {times:2}, 2000);
  46. submit = "no";
  47. return false;
  48. }
  49. if (joined_year == "") {
  50. $("#joined_year").focus()
  51. $("#joinedYear_err").show("pulsate", {times:2}, 2000);
  52. submit = "no";
  53. return false;
  54. }
  55. //If all is good, send to PHP/Database
  56. if (submit != "no") {
  57. $.ajax ({
  58. type: "POST",
  59. url: "../includes/forms/add_member.php",
  60. data: $("#form form").serialize(),
  61. success: function() {
  62. // Dialog
  63. $("#success").dialog({
  64. width: 400,
  65. bgiframe: true,
  66. resizable: false,
  67. modal: true,
  68. title: 'Member Added',
  69. close: function() {
  70. window.location.href = 'add_member.php';
  71. },
  72. overlay: {
  73. backgroundColor: '#000',
  74. opacity: 0.5
  75. },
  76. buttons: {
  77. 'View Members': function() {
  78. window.location.href = 'display_members.php';
  79. },
  80. 'Add Another': function() {
  81. window.location.href = 'add_member.php';
  82. }
  83. }
  84. });
  85. }
  86. });
  87. }
  88. return false;
  89. });