Jump to content

Repopulating drop down on submit


fufaso

Recommended Posts

I'm trying to repopulate a dropdown list when the user hits the submit button to add another item to the dropdown.

 

I'm trying to use the isset method, but am having some issues implementing it properly. Can anyone steer me in the right direction?

 

<html>
<head><title>Dynamic List</title></head>
<body>

<form action="test.php"><select name="list">;
<?  
  
if (isset($_POST['submit'])){    
$file = file("test.txt");
sort($file);
foreach($file AS $country){
    echo "<option>".$country."</option>\n";

}
}
?>

</select>
</form>

please enter your new country:<br>
<form action=test.php method="post">
<input type="text" name="name">: enter your country<br>
<input type="submit" name="submit">
</form>
<?
$file = "test.txt";
$tf = @fopen("$file", "a+");
$name = "\n" . $_POST["name"];
$write = fwrite($tf, $name);
@fclose($file);

?> 
</body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/222071-repopulating-drop-down-on-submit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.