How to Work with Select Box after POST Data in PHP
Everytime We create a form, we used Fields like Text-BOX, Select Box, Radio and Checkbox, Here we will understand a Function to POST data to be selected on database.
PHP Code
<?php
function isselected($value,$optionvalue)
{
if ( $value == $optionvalue )
{
return "selected='selected'";
} else {
return false;
}
}
echo "<form method="POST">";
if(isset($_POST['selectbox']))
{
$valueselected = $_POST['selectbox'];
}
echo "<select name="selectbox">";
echo "<option ".isselected($valueselected,'value1')." value='value1'>value1</option>";
echo "<option ".isselected($valueselected,'value1')."value='value2'>value2</option>";
echo "<option ".isselected($valueselected,'value1')."value='value3'>value3</option>";
echo "<option ".isselected($valueselected,'value1')."value='value4'>value4</option>";
echo "<option ".isselected($valueselected,'value1')."value='value5'>value5</option>";
echo "<option ".isselected($valueselected,'value1')."value='value6'>value6</option>";
echo "</select>";
echo "<input type='submit' value='checkselected' />";
echo "</form>";
?>
Comments
Post a Comment