By: Prem Tiwari | Last Updated:
I got a tutorial request from my website reader, he asked to “Keep values selected after form submission in PHP”. In this tutorial, I will share the simple code to keep form values selected in textbox after form submission.
Let’s start to create an example for this. Copy the below code and change it as per your requirement.
$example = $_POST["example"];
<option <?php if (isset($example) && $example=="a") echo "selected";?>>a</option>
<option <?php if (isset($example) && $example=="b") echo "selected";?>>b</option>
<option <?php if (isset($example) && $example=="c") echo "selected";?>>c</option>
<input type="submit" name="submit" value="submit" />
<select name="name" id="name">
document.getElementById('name').value = "<?php echo $_GET['name'];?>";
Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.View all posts by Prem Tiwari