tags:

views:

52

answers:

1

I'd like to compute a value and carry that computation in the form post, so what I do is:

<form>
<input name="myID" id="myID" type="hidden" />
</form>
$('#myID').attr('value',myCalculation);

What I would like to do is display it as well, so I've added:

<div id="myIDdisplay"></div>
$('#myIDdisplay').text(myCalculation);

Is there a better, more elegant way than duplicating the assignment of myCalculation to both the hidden form field and the displayed area?

I don't want the user to get confused in thinking that it's an input field, so I'd rather not display the input tag. And I just can't trust CSS enough to think that CSS will remove the input border on every version of every browser.

+4  A: 

I think this is, perhaps, the best solution. If you tried to use a single field, you'd need to make that field disabled (presumably) so that the user couldn't change it directly. If you do that, it won't post back with the form, so then you'd need to add some code to enabled it before posting. That's probably more code than what you have.

tvanfosson
+1 i don't think there's anything wrong w/the OP's solution
Jason