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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵