admin管理员组文章数量:1391943
I have a form which calculates a cost and sets the value of an input accordingly. For obvious reasons, I have used:
$('#totalcost').attr('disabled',true);
to prevent the user from being able to edit the cost.
However, when I do this, the PHP script I'm using to mail the form doesn't pick up the input (not just the value - it doesn't read the input at all). When the input is enabled, it works fine.
How can I prevent the user from editing the input while still having the PHP mailing the value? Or is there a better way to do this anyway?
I have a form which calculates a cost and sets the value of an input accordingly. For obvious reasons, I have used:
$('#totalcost').attr('disabled',true);
to prevent the user from being able to edit the cost.
However, when I do this, the PHP script I'm using to mail the form doesn't pick up the input (not just the value - it doesn't read the input at all). When the input is enabled, it works fine.
How can I prevent the user from editing the input while still having the PHP mailing the value? Or is there a better way to do this anyway?
Share Improve this question asked Nov 28, 2013 at 12:54 ElendilTheTallElendilTheTall 1,46218 silver badges26 bronze badges 3-
The values of disabled form elements are not send – this is explicitly specified this way. Use
readonly
instead. – C3roe Commented Nov 28, 2013 at 12:56 - Well better place an hidden field also , this might help stackoverflow./questions/6241943/… – Deepanshu Goyal Commented Nov 28, 2013 at 12:58
-
Then again, inputs can still be edited after pressing submit, an example tool would be the Firefox extension:
tamperdata
– Daryl Gill Commented Nov 28, 2013 at 12:59
6 Answers
Reset to default 7Make it readonly, not disabled:
$("#totalcost").attr('readonly', true);
You could also do it in the original HTML, since it's not something you really want to change back and forth dynamically.
<input id="totalcost" type="text" readonly>
Use Read Only property, Though i guess it wont work in internet exploer.
Add readonly attribute, like this:
$("#totalcost").attr('readonly', true);
Add property readonly="true".
$('#totalcost').attr('readonly',true);
you can try:
$("#totalcost").prop("readonly",true);
Use read only in html itself or in script
<input type="text" name="totalcost" id="totalcost" value="" readonly>
$('#totalcost').attr("readonly", true);
本文标签: javascriptMaking an input noneditable without disablingStack Overflow
版权声明:本文标题:javascript - Making an input non-editable without disabling - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744734483a2622241.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论