Skip to content

Commit 2141664

Browse files
committed
List service options programmatically
Make an array which holds service name and corresponding string Print the select options into HTML with that If an item was selected on last run, mark it as selected again.
1 parent 3765389 commit 2141664

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

index.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,26 @@
5050

5151
<form name="input" action="index.php" method="get"><p>
5252
<select name="service">
53-
<option value="traceroute">traceroute</option>
54-
<option value="traceroute6">traceroute (IPv6)</option>
55-
<option value="ping">ping</option>
56-
<option value="ping6">ping (IPv6)</option>
57-
<option value="nslookup">nslookup</option>
53+
<?php
54+
55+
$services_array = array(
56+
"traceroute" => "traceroute",
57+
"traceroute6" => "traceroute (IPv6)",
58+
"ping" => "ping",
59+
"ping6" => "ping (IPv6)",
60+
"nslookup" => "nslookup",
61+
);
62+
63+
// List options programmatically
64+
// output should look like
65+
// <option value="ping" selected="selected">ping</option>
66+
foreach($services_array as $s => $v) {
67+
echo ' <option value="'.$s.'"';
68+
if ($s == $_GET['service'])
69+
echo ' selected="selected"';
70+
echo '>'.$v.'</option>'."\n ";
71+
}
72+
?>
5873
</select>
5974
IP ADDRESS:
6075
<input type="text" name="address" value="<?php echo trim($_GET['address']); ?>"/>

0 commit comments

Comments
 (0)