Page 1 of 1
[SOLVED]How to Valid a drop down in JS
Posted: Tue May 25, 2004 3:46 pm
by Draco_03
I have this code
Code: Select all
if (document.commande.fax.value=="") {
alert("Veuillez inscrire votre numero de fax")
return (false)
}
That just basically test if he entered a value in a texte area BUT when i need to valid a DROP down menu..
what's the code?
i'm not good with javascript..
thx in advance
Posted: Tue May 25, 2004 4:05 pm
by feyd
Code: Select all
<select onchange="validation code/function here">
<option value="blah">
</select>
the validation code would access the value of the selected option.. so
Code: Select all
this.optionsїthis.selectedIndex].value
Posted: Tue May 25, 2004 4:12 pm
by Draco_03
I have a function actually
Code: Select all
function checkform(commande)
{
if (document.commande.firstname.value=="") {
alert("Veuillez inscrire votre prénom")
return (false)
}
if (document.commande.lastname.value=="") {
alert("Veuillez inscrire votre nom de famille")
return (false)
}
and so on
and my form
Code: Select all
<select name="lignes" class="lignes">
<option value="--">--</option>
<option value="ren">Renaissance</option>
<option value="oxy">Oxygene Botanical</option>
<option value="bio">Biocella</option>
<option value="atzen">Atzen</option>
<option value="adeeva">Adeeva</option>
<option value="escential">Escential</option>
</select>
so i would like to actually add the check in my function (i call my function on submit)
Posted: Tue May 25, 2004 4:17 pm
by feyd
mkay..
Code: Select all
var select = document.commande.lignes;
if(select && select.optionsїselect.selectedIndex].value == '--')
{
alert('nothing selected');
return false;
}
Posted: Tue May 25, 2004 4:24 pm
by Draco_03
Thx Feyd...
