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条)

报告相同问题?

悬赏问题

  • ¥15 如何使用Echarts制作途中时间序列表
  • ¥15 图论相关的数学问题,共10个
  • ¥15 EtherCAT的问题,创建一个XML文件
  • ¥15 微信公众号羽毛球自动抢定场程序制作
  • ¥15 Fluent UDF 编写
  • ¥15 xcode开发的macos应用,如何使窗口居中显示?
  • ¥20 统信uos升级apt后启动失败
  • ¥15 求指导储层饱和度及含水率测井解释
  • ¥200 建三维地震工区写入sgy到指定目录
  • ¥30 靶向捕获测序探针设计自学