here's the whole thing...
[php]<html>
<head>
<script language="JavaScript" type="text/javascript">
function removeIP(v)
{
// remove IP address from list
document.forms[0].ipList[v] = null;
}
function checkIP(v)
{
var check = 0;
// creates an array from the sections of an IP address
// 192.168.254.2 would be ipSub(192, 168, 254, 2)
var ipSub = v.split(".");
// checks to make sure a valid IP address is entered
for (i = 0; i < ipSub.length; ++i)
{
// checks to ensure that only numbers were entered for the IP address
for (j = 0; j < ipSub[i].length; ++j)
{
// verifies that each character is a number
var abc = parseFloat(ipSub[i].charAt(j));
// if something other than a number is found, an alert is posted
if (isNaN(abc)) { alert("Character " + ++j + " in section " + ++i + " is not a number."); ++check; }
}
// if an element of the array ipSub has more than 3 characters, an alert is posted
if (ipSub[i].length > 3) { alert("Invalid IP address, section " + ++i + " is too long."); ++check; }
// if an elembent of the array ipSub is greater than 255, an alert is posted
if (ipSub[i] > 255) { alert("Invalid IP address, section " + ++i + " is out of range."); ++check; }
}
// adds to list if valid
if (check == 0)
{
// increase the number of options by 1
++document.forms[0].ipList.length;
// add text to the new option
document.forms[0].ipList[(document.forms[0].ipList.length - 1)].text = v;
}
}
function submitIP(v)
{
// selects all values in list box
for (i = 0; i < v.length; ++i)
{
v[i].selected = "true";
}
// changes the name of the <select> tag to match an array for PHP processing
document.forms[0].ipList.name = "ipList[]";
}
</script>
</head>
<body>
<form name="ipForm" method="post" action="<? echo $PHP_SELF ?>">
<select name="ipList" size="10" multiple>
<option>192.168.254.2</option>
<option>192.168.254.3</option>
<option>192.168.254.4</option>
</select>
<a href="javascript
:removeIP(document.forms[0].ipList.selectedIndex)">Remove</a>
<br> <br>
<input type="text" name="add_ip">
<a href="javascript
:checkIP(document.forms[0].add_ip.value)">Add</a>
<br>
<input type="submit" name="submit" value="Submit" onClick="javascript
:submitIP(document.forms[0].ipList);">
</form>
<?
if (!$_POST['submit'])
{
echo "form not submitted";
}
else
{
echo "<b>IP Addresses from list:</b> <br>";
for ($i=0; $i < count($ipList); $i++)
{
echo "$ipList[$i] <br>";
}
}
?>
</body>
</html>[/php]
see it
here.