Basically the program is user enter number of the month for example : 12, then if you click the submit button, it will showed the name of the month, in this case December.
The problem is every time I click submit the value in textbox disappeared, I want the textbox still containing "12" even after the submit button is clicked.
Ps : Don't mind the non-English words.
<form method = "post">
4. Insert month(1-12) :
<input type="text" name="monthTxt" value=""><br/>
<input type="submit" value="Submit">
</form>
<?php
$monthTemp = $_POST["monthTxt"];
$testing = $monthTemp;
function bulan($bulan)
{
$months = array(1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'December');
if($bulan < 1 || $bulan > 12)
{
echo "Input tidak boleh kurang dari 0, lebih dari 12, atau huruf";
}
else
{
echo $months[$bulan];
}
}
bulan($monthTemp);
?>
Without changing this all to AJAX, you need to include the POST variable in the form if it has been set. Change the form field's value attribute to the following:
<input type="text" name="monthTxt" value="<?php if (isset($_POST['monthTxt'])) { echo $_POST['monthTxt']; } ?>">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With