dousong4777 2013-02-01 17:40
浏览 42
已采纳

在fieldset中添加验证消息而不是js popup

I have a php app, that has been pieced together, but I am working on an crazy validation piece, that i've got working. At the end of the validation, the following function runs and gives me a popup with the listed of required fields.

function showReqFlds(emptyFlds) {
    for (var i = 0; i < emptyFlds.length; i++) {
    var holdErrMsgs = emptyFlds[i]+' is required.' + "
";

    }
        alert(holdErrMsgs);
}

Works great, but now I want instead of the javascript popup box, I want the error messages to appear in a fieldset at the top of my form.

Steps:

User opens form, error fieldset is not displaying User clicks the submit button to submit form, but has not filled in a couple of the required fields Error fieldset appears, shows required field list, form is not submitted.

Any assistance would be appreciate. Thank you.

  • 写回答

2条回答 默认 最新

  • doulei8861 2013-02-01 18:29
    关注

    Just think about this:

    function changeText(text)
    {
    elem = document.getElementById('error_message');
    elem.innerHTML = text;
    }
    

    And you have in your html page this:

     <div id='error_message'>I'm a error message</div>      
     <button onclick="changeText('error1');">error1</button>
     <button onclick="changeText('error2');">error2</button>
    

    With something like this you should do the trick.

    Saludos.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?