Problem with Javascript function......Please Help

Hi,

I am using a javascript given below, but this is not working for the company condition. I am calling a company name from database such as:

Company Name (LOCATION)
Company Name2 (LOCATION)

The script having following problems:

  1. Its not checking NULL value for the text box “Keyword”.
  2. If I am writing something without “()” it doesn’t search. But It works fine when I added “()” after any company name.

Please let me know where I mistook.


function doSearch()
 {
        //alert("I am here");
        doSub=true; var dd = document.getElementById('city_name');
        var areaname=document.getElementById('keyword').value; var c = document.getElementById('city_name').value;
        if(document.getElementById('company').checked){
            var areaname_x = areaname.split("  (");
            var areaname_y = areaname_x[1].split(")");
            //change the action value of the first form
            document.getElementsByTagName('form')[0].action="srch/serch_name.php?city="+c+"&title="+encodeURIComponent(areaname_x[0])+"&area="+escape(areaname_y[0])+"";
            if(document.getElementById('city_name').value==""||document.getElementById('city_name').value=="Select City")
            {
                alert("Please select city first!");
                document.getElementById('city_name').focus();
                    doSub=false;
               }

            else if(document.getElementById('keyword').value==""){
                alert("Please enter category / company name for search.");
                document.getElementById('keyword').focus();
                   doSub=false;
            }
        }
        
        else{ var b=document.getElementById('keyword').value; var c = document.getElementById('city_name').value;
            document.getElementsByTagName('form')[0].action="srch/serch_keywords.php?city="+c+"&title="+encodeURIComponent(b)+"";
           if(document.getElementById('city_name').value==""||document.getElementById('city_name').value=="Select City"){
                alert("Please select city first!");
                document.getElementById('city_name').focus();
                    doSub=false;
               }
            else if(document.getElementById('keyword').value==""){
                alert("Please enter category / company name for search.");
                document.getElementById('keyword').focus();
                doSub=false;
            }
        }
        //submit the form
        if(doSub===true){
            document.getElementsByTagName('form')[0].submit();
        }
}

Your help would be highly appreciated.

Thanks