...

View Full Version : Question regarding form validation



dream_theory
05-29-2006, 04:19 AM
Please look at my code:

<SCRIPT>
function validate()
{
ver3=addip.IP3.value;
ver4=addip.IP4.value;
vermac=addip.mac.value;

if (!(ver3>=1 && ver3<=12))
{
alert('Valid 3rd Octet is 0-12');
event.returnValue=false;
}

if (!(ver4>=31 && ver4<=210))
{
alert('Valid 4th Octet is 31-210');
event.returnValue=false;
}

if (vermac=='')
{
alert('MAC Address is required');
event.returnValue=false;
}

}
</SCRIPT>

If I substitute the number 0 to this line:
if (!(ver3>=1 && ver3<=12))
where it will be
if (!(ver3>=0 && ver3<=12))

the code doesn't work, please help me fix it tnx

Philip M
05-29-2006, 07:36 AM
It works fine for me when I test it. Why should it not work?

<SCRIPT>
function validate()
{
ver3=15;
ver4=4;
vermac='';

if (!(ver3>=0 && ver3<=12))
{
alert('Valid 3rd Octet is 0-12');
event.returnValue=false;
}

Kor
05-29-2006, 09:33 AM
Ii woun't work as desired because the attribute's values return strings not numbers. And the objects are not referenced correctly. The root is document

should have been

ver3=Number(document.addip.IP3.value);
ver4=Number(document.addip.IP4.value);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum