douguachan2879 2009-09-05 01:49
浏览 43
已采纳

跟踪html表单控件的数据库表/列的最佳方法

I am working on a php program that requires javascript on every form control. Once the onblur event takes place the value will automatically be sent to the server to update the database.

I have possibly 50 form controls spread over 5 tabs so I don't want to hardcode the information on the php file.

I could co-opt an idea from HTML5 and create new properties for this such as

data-table='user' data-column='firstname'

for every item, and then javascript could pull those values out and send them to the php file.

I don't know if there is a better way to manage the mapping between these form controls and the several tables/columns?

  • 写回答

3条回答 默认 最新

  • dpw30157 2009-09-05 02:30
    关注

    HTML

    <input id='data-base*data-colum' onblur='preupdate(this);' value='' />
    

    Javascript

    function preupdate(el){
       var idData = el.getAttribute('id').split('*');
       var dataBase = idData[0];
       var dataColum = idData[1];
    
       update(el.value, dataBase, dataColum);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?