1040 || parseint(document.getElementById("postcode").value.substring(0,4)) { document.getElementById("plaatsnaam").value="Amsterdam" }else if(document.getElementById("postcode").value.substring(0,4)=="1050-1059") { document.getElementById("plaatsnaam").value=" Amsterdam" }}Hope you can help me out! Is in the parseint? Or just a typing error, I don't see it anymore. Thanks!Cynthia"> Javascript if field between values - Forums

Forums

Javascript if field between values

ultima 20 Sep, 2010
Hi all,

I am working on a form for users to upload data and want to fill a certain field based on the value in the field before. That is working, but rather then having to code every single possible value, I want to use an in between check. See below in bold the part I can't get to work:

function plaats_chk()
{if(document.getElementById("postcode").value=="3162PH")
{
document.getElementById("plaatsnaam").value="Rhoon"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1000-1025")
{
document.getElementById("plaatsnaam").value=" Amsterdam"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1010-1019")
{
document.getElementById("plaatsnaam").value="Amsterdam"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1020-1025")
{
document.getElementById("plaatsnaam").value=" Amsterdam"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1026")
{
document.getElementById("plaatsnaam").value=" Durgerdam"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1027")
{
document.getElementById("plaatsnaam").value="Amsterdam"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1028")
{
document.getElementById("plaatsnaam").value="Amsterdam"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1030-1099")
{
document.getElementById("plaatsnaam").value=" Amsterdam"
}
else if(document.getElementById("postcode").value.substring(0,4)=="1030-1039")
{
document.getElementById("plaatsnaam").value=" Amsterdam"
}
else if (parseint(document.getElementById("postcode").value.substring(0,4)) > 1040 || parseint(document.getElementById("postcode").value.substring(0,4)) < 1049)
{
document.getElementById("plaatsnaam").value="Amsterdam"
}


else if(document.getElementById("postcode").value.substring(0,4)=="1050-1059")
{
document.getElementById("plaatsnaam").value=" Amsterdam"
}
}


Hope you can help me out! Is in the parseint? Or just a typing error, I don't see it anymore.

Thanks!


Cynthia
Max_admin 20 Sep, 2010
Hi Cynthia,

I'm not sure I understand your question but maybe you try to use an array of values and use the mootools contains function:

http://mootools.net/docs/core/Native/Array#Array:contains

Pay attention to the mootools version, I'm not sure if contains is in Moo1.1

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
GreyHead 24 Sep, 2010
Hi Cynthia,

You need to check your logic a little. This kind of statement won't work the way you expect it to:
substring(0,4)=="1000-1025") 
A four character substring can never be equal to a 9 character string.

Bob
This topic is locked and no more replies can be posted.