Forum Moderators: coopster

Message Too Old, No Replies

how to write code in "hidden" input fields

         

michlcamp

11:30 pm on Jul 18, 2005 (gmt 0)

10+ Year Member



Can anyone tell me how to write this code as value=

in hidden form input?

<?php if ($total > 81.75) {printf ("%01.2f", $total * .11);}else {echo "8.99 ";}?>

it calculates shipping costs and I have to pass the result on to the next pages...

this doesn't work, of course, but you get the idea...:

<input type="hidden" value="<?php if ($total > 81.75) {printf ("%01.2f", $total * .11);}else {echo "8.99 ";}?>" ">

thanks a million. This forum is excellent.
mc

sned

11:46 pm on Jul 18, 2005 (gmt 0)

10+ Year Member



Actually, it looks like it should work just how you've written it. (minus the very last ")

Another way to do it could be like this:

<?php
if($total > 81.75){
$value = printf ("%01.2f", $total * .11);}
else{
$value = "8.99 ";
}
?>
<input type="hidden" name="somename" value="<?php echo $value;?>" />

-sned

<edit>
added the somename thing
</edit>

michlcamp

12:34 am on Jul 19, 2005 (gmt 0)

10+ Year Member



Well, that does the computation but doesn't post to the next page properly - I get a parsing error. Also, the printf prints on the page on its own

coopster

12:46 pm on Jul 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, michlcamp.

I can't see where this portion of the code would be giving a parsing error, except for the "printf" part here. Use printf when you want to output the data, use sprintf [php.net] if you want to format and assign the value to a variable.