Q:

validate textbox & run another function javascript

I have textboxes & button on button click I am trying to open lightbox popup which is working.  Problem is First it needs to check for validation If validation is true then only it should run popup function.  But it's not happening.  If textbox is empty then it shows alert but if I click ok On alert box then it immediately opens popup box.  Following is my code
JS
function validate() {
  if (document.getElementById("txtSource").value == "") {
    alert("Please Enter Pick up location");
  } else if (document.getElementById("txtDestination").value == "") {
    alert("Please Enter Drop off location");
  } else if (document.getElementById("selectVehicle").value == "Select Vehicle")
    alert("Please Select Vehcile.") 
    return true;
}

$(document).ready(function() {
  $("#hidePopup").click(function() {
    $('.booking-popup').css('visibility', 'hidden');
  });

  $("#openPopup").click(function() {
    $('.booking-popup').css('visibility', 'visible');
  });
});

Page Code
<asp:TextBox name="fname" ID="txtSource" onchange="GetRoute()" onblur="GetRoute()" runat="server" CssClass="inners" placeholder="From Area"></asp:TextBox>
<asp:TextBox ID="txtDestination" onchange="GetRoute()" onblur="GetRoute()" runat="server" CssClass="inners" placeholder="To Area"></asp:TextBox>
<p>&nbsp;</p>
<asp:DropDownList ID="selectVehicle" onchange="GetRoute();" AutoPostBack="true" runat="server" CssClass="inners">
  <asp:listitem Value="SelectVehicle" Selected>-- Select Vehicle --</asp:listitem>
  <asp:ListItem Value="20">Tata Ace</asp:ListItem>
  <asp:ListItem Value="25">Bolero Pick Up</asp:ListItem>
  <asp:listitem Value="30">Tata 407</asp:listitem>
  <asp:listitem Value="35">14 Feet</asp:listitem>
</asp:DropDownList>

<p>&nbsp;</p>
<asp:Button ID="openPopup" OnClientClick="validate(); GetRoute();" runat="server" CssClass="book" Text="GET QUICK QUOTE" />

A:

return false in invalid and add if valid to $("#openPopup").click(function () {:-
function validate() {
  if (document.getElementById("txtSource").value == "") {
    alert("Please Enter Pick up location");
    return false;
  } else if (document.getElementById("txtDestination").value == "") {
    alert("Please Enter Drop off location");
    return false;
  } else if (document.getElementById("selectVehicle").value == "Select Vehicle") {
    alert("Please Select Vehcile.") 
    return false;
  }

  return true;
}

 $("#openPopup").click(function () {
     if(validate())
       $('.booking-popup').css('visibility', 'visible');
 });

