hunt
hunt

Reputation: 321

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!");
    }
    else
    {
        validateDuplicate(name);
        this.up('window').close();  
    }
}

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.

Upvotes: 2

Views: 98

Answers (3)

Manish Parakhiya
Manish Parakhiya

Reputation: 3798

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

if(errors.length>0){
    Ext.Msg.alert(errors);
}

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

Upvotes: 2

Dwight
Dwight

Reputation: 730

try if statement like this: if (x==" && y==" && z=") { //do stuff } or this

if (x==" || y==|| z==)
{
//do stuff
}

Upvotes: 1

Aashish Kumar
Aashish Kumar

Reputation: 1643

You can do this just by using OR operator but in this case your alert message would be generic as.

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 == ''|| loa == '' || DWT == '' || GrossTonnage == '') {

Ext.Msg.alert("You need to fill all the text field");
}

else {
validateDuplicate(name);

this.up('window').close();  
}
}

Upvotes: 7

Related Questions