Search code examples
asp.net-mvc-3visual-studio-2010dhtmlx

Validate at least one field is filled in dhtmlx form


I have text boxes and drop downs in my form.and I have a button named"search". When I enter the values and click on the search button I have display the search results.

Entering all values is not required, user has to enter at least one value otherwise we have to give validation message that Enter at least one value. How can I do this validation?

I gave like:

var fn = myForm.getItemValue("FirstName");
var ln = myForm.getItemValue("LastName");
var c = myForm.getItemValue("City");
var st = myForm.getItemValue("State");
var cnt = myForm.getItemValue("Country");
var zc = myForm.getItemValue("Zipcode");
var em = myForm.getItemValue("Email");
var ph = myForm.getItemValue("Phone");
if (fn == "" && ln == "" && c == "" && st == "" && zc == "" && em == "" && ph == "" ) {
alert("please enter atleast one value");
}

My alert is working fine, but I want to display validation message in the form that "please enter at least one field" at the top of the form. How can I do this?


Solution

  • At the top of the form add a div

    <div id="message"></div>
    

    In your script, in place of the alert:

    $("#message").html("");