Angie Angie - 1 month ago 7
PHP Question

Use current values as placeholders in form

I am almost done with a complex calculator, but have a minor issue. After the user presses the calculate button, all the values in the fields are removed. I have tried adding the appropriate variable in the placeholder, but when I do that, the placeholder displays the value that I set as default when I initialized it. I assume this is happening because the calculate button is forcing the page to refresh. What are my options here to keep the updated values in the fields.

Also ... for my future reference...is php not the way to go in this circumstance? Would java or html have been better choices?

My code can be viewed here: https://github.com/DTAngie/LearningProjects/blob/master/ComplexCalc

and you can view the result at: http://distechs.com/development

Answer
"<?php echo $annlAvgFranchisees; ?>"><?php if(isset($_POST['calculate'])) {
        $annlAvgFranchisees = $_POST['Annl-avg-franchisees'];
    } ?>

You write your variable before it set.

How about

 if(isset($_POST['calculate'])) {
            Echo  $_POST['Annl-avg-franchisees']; } else { echo $annlAvgFranchisees;}

Or you can make it shorter with ternarry

Echo (isset($_POST['calculate'])) ? $_POST['Annl-avg-franchisees']  : $annlAvgFranchisees;)