dqy012345 2014-03-22 23:59
浏览 232
已采纳

如何防止更改预设的INPUT值?

I have a form where some fields are completed by loading information from a database. These fields can vary from one account to another.

When the form is submitted any database information will be sent along with new information entered in the form.

However, the user is able to change (on screen) the information entered from the database, and although these changes are not submitted (my $Xvariables from the database override the POSTed $variables), I would like them to revert the on-screen data back to the database value.

Here is an example of what I have at the moment, but it does not work ...

  <input type="text" name="firstname" size="25" tabindex="4" onchange="if($xfirstname<>'') this.value=$xfirstname" value="<?php echo $firstname;?>"/>

or better still, if there is a way, how can I make them unchangable if they have a value loaded from the database ?

  • 写回答

2条回答 默认 最新

  • douzhuican0041 2014-03-23 00:05
    关注

    Keep this:

    <input type="text" name="firstname" size="25" tabindex="4"
     value="<?php echo $firstname;?>"/>
    

    Add this: Edit: Sorry did not see it has no ID on the input element use this:

    <script>
    if($('input[name="firstname"]').val().length > 0)
    {
    $('input[name="firstname"]').attr("disabled", true);
    }
    </script>
    

    Result :http://jsfiddle.net/4wt9r/6/

    But keep in mind anything on the client can be changed, your true filtering/authenticating must be done on the server.

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

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?