ElendilTheTall
ElendilTheTall

Reputation: 1452

Making an input non-editable without disabling

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

Answers (6)

user3040610
user3040610

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

JosephC
JosephC

Reputation: 166

you can try:

$("#totalcost").prop("readonly",true);

Upvotes: 0

Tom Chung
Tom Chung

Reputation: 1422

Add property readonly="true".

$('#totalcost').attr('readonly',true);

Upvotes: 0

display-name-is-missing
display-name-is-missing

Reputation: 4399

Add readonly attribute, like this:

$("#totalcost").attr('readonly', true);

Upvotes: 0

sushil bharwani
sushil bharwani

Reputation: 30187

Use Read Only property, Though i guess it wont work in internet exploer.

Upvotes: 0

Barmar
Barmar

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

Related Questions