Form Validation using JavaScript

后端 未结 5 1266
-上瘾入骨i
-上瘾入骨i 2021-01-25 02:44

I\'m trying to validate a form using JavaScript but i\'m a bit stuck on displaying a message next to the field to say that \"This field is required\". How do I go about doing th

5条回答
  •  长发绾君心
    2021-01-25 03:32

    Simplest way is to put a hidden span tag below the input field like so

     

    In Javascript you can do this

    if(!valid)
    {
      document.getElementById("fieldname").style = "block";
    }
    

提交回复
热议问题