Reputation: 1452
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?
Upvotes: 0
Views: 3355
Reputation: 760
Use read only in html itself or in script
<input type="text" name="totalcost" id="totalcost" value="" readonly>
$('#totalcost').attr("readonly", true);
Upvotes: 0
Reputation: 1422
Add property readonly="true".
$('#totalcost').attr('readonly',true);
Upvotes: 0
Reputation: 4399
Add readonly attribute, like this:
$("#totalcost").attr('readonly', true);
Upvotes: 0
Reputation: 30187
Use Read Only property, Though i guess it wont work in internet exploer.
Upvotes: 0
Reputation: 780889
Make 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>
Upvotes: 6