Forum Moderators: open
I want to make sure that, when a certain checkbox is checked, the following input field (text field) cannot be empty.
The code I have so far doesn't work, however. (x is the variable holding the name of my form: x=document.myform )
valid_cbox_field2=x.information.checked
valid_inp_field=x.reaction
if ( valid_cbox_field2 == true && valid_inp_field == false )
{
alert ("Please specify which information you wish to obtain.")
return false;
}
Why doesn't it return an alertbox when the checkbox is checked and the text field is empty?
it doesn't... I left out the '[red]' text though. I guess that stands for 'redacted' or something?
Here is the full script:
function validate()
{
x=document.myform;geldigenaam=x.naam.value;
if (geldigenaam == "")
{
alert("Vul aub de naam en voornaam van de contactpersoon in.")
return false
}
geldigadres=x.straat_nummer.value;
if (geldigadres == "")
{
alert("Vul aub het adres in.")
return false
}
geldigepostcode=x.postcode.value;
if (geldigepostcode == "")
{
alert("Vul aub de postcode in.")
return false
}
geldigegemeente=x.gemeente.value;
if (geldigegemeente == "")
{
alert("Vul aub de gemeente in.")
return false
}
geldigaanvinkveld1=x.abonnement_op1lijnkrant.checked
geldigaanvinkveld2=x.informatie_campagne.checked
if ( geldigaanvinkveld1 == false && geldigaanvinkveld2 == false )
{
alert("U dient minstens 1 van de 2 invulvelden aan te vinken om te weten te komen wat u wenst.");
return false
}
valid_inp_field=x.reaction.value;
if ( valid_cbox_field2 == true && valid_inp_field == "" )
{
alert ("Please specify which information you wish to obtain.")
return false;
}
I think I'm finally coming to grips with this Javascript stuff. I'm good at coding, but not programming! I really need exercises like these B)
Thanks again, you're very helpful.