Hi to all

i make an HTML page and after entering the data when user press the submit button the data stored in database. i also make validation that which text field is optional and which text field is necessary to fulfill.but the problem is that i have 3 text field MAC Address, CPU ID and motherboard ID . In MAC, CPU and Mother board ID One at least is provided.that may be MAC ,CPU ID or Motherboard ID.

how can i validate this....please help

Member Avatar for stbuchok

Pretty sure this is about how it should work.

var cpu = document.getElementById('txtCPU');
var mac = document.getElementById('txtMAC');
var mobo = document.getElementById('txtMOBO');

if(!isNullOrEmpty(cpu) || !isNullOrEmpty(mac) || !isNullOrEmpty(mobo)){
    //at least one is filled out.
}
else{
    //none are filled in.
}

function isNullOrEmpty(element){
    var blnFlag = true;

    if(typeof element === 'undefined' || element === null || element.value === ''){
        blnFlag = true;
    }
    else {
        blnFlag = false;
    }

    return blnFlag;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.