How to create an array text box to lessen the codes
==========================
==========
=======
I have a total of four IP addresses that may (optional not mandatory) to be filled in.
Each Ip address have four separate fields. This gives a total
of 16 fields. The code below showed that codes has to be
written for these individual fields.
1) Is there a way to declared in HTML that these fields are arrays
so that I could access them by subscript (ex: array[1] to array[16]) to lessen the codes ?
==========================
==========
=======
[code]
<script LANGUAGE="Javascript">
<!--
function check_for_all_0_and_all_25
5(ip_addre
ss)
{
if (ip_address.name == "ip1" ||ip_address.name == "ip2" ||
ip_address.name == "ip3" ||ip_address.name == "ip4")
{
field_name_1 = "ip1";
field_name_2 = "ip2";
field_name_3 = "ip3";
field_name_4 = "ip4";
}
if (ip_address.name == "ip1opt" ||ip_address.name == "ip2opt" ||
ip_address.name == "ip3opt" ||ip_address.name == "ip4opt")
{
field_name_1 = "ip1opt";
field_name_2 = "ip2opt";
field_name_3 = "ip3opt";
field_name_4 = "ip4opt";
}
if (ip_address.name == "ip1opt1" ||ip_address.name == "ip2opt1" ||
ip_address.name == "ip3opt1" ||ip_address.name == "ip4opt1")
{
field_name_1 = "ip1opt1";
field_name_2 = "ip2opt1";
field_name_3 = "ip3opt1";
field_name_4 = "ip4opt1";
}
if (ip_address.name == "ip1opt2" ||ip_address.name == "ip2opt2" ||
ip_address.name == "ip3opt2" ||ip_address.name == "ip4opt2")
{
field_name_1 = "ip1opt2";
field_name_2 = "ip2opt2";
field_name_3 = "ip3opt2";
field_name_4 = "ip4opt2";
converted_ip1 = parseInt(document.form1[fi
eld_name_1
].value)
converted_ip2 = parseInt(document.form1[fi
eld_name_2
].value)
converted_ip3 = parseInt(document.form1[fi
eld_name_3
].value)
converted_ip4 = parseInt(document.form1[fi
eld_name_4
].value)
if (converted_ip1 == 0 && converted_ip2 == 0 && converted_ip3 == 0 && converted_ip4 == 0)
{
alert ("The IP value cannot be 0.0.0.0");
document.form1[field_name_
1].value = "";
document.form1[field_name_
2].value = "";
document.form1[field_name_
3].value = "";
document.form1[field_name_
4].value = "";
return false;
}
if (converted_ip1 == 255 && converted_ip2 == 255 && converted_ip3 == 255 && converted_ip4 == 255)
{
alert ("The IP value cannot be 255.255.255.255");
document.form1[field_name_
1].value = "";
document.form1[field_name_
2].value = "";
document.form1[field_name_
3].value = "";
document.form1[field_name_
4].value = "";
return false;
}
}
<input type=text size=3 maxlength=3 name=ip1 onkeyup='only_numbers(ip1)
' onblur='check_for_over_255
(ip1); check_for_all_0_and_all_25
5(ip1)' value="<?=$lv_ip01?>">&nbs
p;<b>.</b>
<input type=text size=3 maxlength=3 name=ip2 onkeyup='only_numbers(ip2)
' onblur='check_for_over_255
(ip2); check_for_all_0_and_all_25
5(ip2)' value="<?=$lv_ip02?>">&nbs
p;<b>.</b>
<input type=text size=3 maxlength=3 name=ip3 onkeyup='only_numbers(ip3)
' onblur='check_for_over_255
(ip3); check_for_all_0_and_all_25
5(ip3)' value="<?=$lv_ip03?>">&nbs
p;<b>.</b>
<input type=text size=3 maxlength=3 name=ip4 onkeyup='only_numbers(ip4)
' onblur='check_for_over_255
(ip4); check_for_all_0_and_all_25
5(ip4)' value="<?=$lv_ip04?>">
</td>
//-->
</SCRIPT>
[/code]