hunt hunt - 1 year ago 66
Javascript Question

How to validate all empty text once in .NET

function save() {

var iframeID = $('iframe').attr('id');

var code = lazyMethod_get(iframeID, "form1", "txt_code");
var loa = lazyMethod_get(iframeID, "form1", "txt_loa");
var DWT = lazyMethod_get(iframeID, "form1", "txt_dwt");
var GrossTonnage = lazyMethod_get(iframeID, "form1", "txt_gross");

if (code == '')
Ext.Msg.alert("Code need to be fill in!");
else if (loa == '')
Ext.Msg.alert("LOA need to be fill in!");
else if (DWT == '')
Ext.Msg.alert("DWT need to be fill in!");
else if (GrossTonnage == '')
Ext.Msg.alert("Gross Tonnage need to be fill in!");

Above is the code i done and it prompt one by one. I need it to validate just once if the user miss out 2 of the textbox it will prompt the error once and not two times.

Answer Source

Instead of alert in every condition you can append error in variable and then alert ones.

var errors=''; 
if (code == '') {

    errors+="Code need to be fill in!";
if (loa == '') {

    errors+="LOA need to be fill in!";

After all condition check if any error and then alert


This is javascript example. same can be applied for C# also

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download