Checking if a textbox is empty in Javascript

前端 未结 3 1301
孤街浪徒
孤街浪徒 2020-12-08 11:26

This is my code which was supposed to raise an alert message if the textbox is left empty:

function a(id)
{
    var n=document.getElementById(id         


        
3条回答
  •  广开言路
    2020-12-08 11:55

    your validation should be occur before your event suppose you are going to submit your form.

    anyway if you want this on onchange, so here is code.

    function valid(id)
    {
        var textVal=document.getElementById(id).value;
        if (!textVal.match(/\S/)) 
        {
            alert("Field is blank");
            return false;
        } 
        else 
        {
            return true;
        }
     }
    

提交回复
热议问题