[SOLVED]How to Valid a drop down in JS

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

[SOLVED]How to Valid a drop down in JS

Post 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
Last edited by Draco_03 on Tue May 25, 2004 4:24 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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&#1111;this.selectedIndex].value
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

I have a function actually

Code: Select all

function checkform(commande)
&#123;
	if (document.commande.firstname.value=="") &#123;
	alert("Veuillez inscrire votre prénom")
	return (false)
	&#125;
	
	if (document.commande.lastname.value=="") &#123;
	alert("Veuillez inscrire votre nom de famille")
	return (false)
	&#125; 
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)

Code: Select all

onsubmit="return checkform(this)"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mkay..

Code: Select all

var select = document.commande.lignes;
if(select && select.options&#1111;select.selectedIndex].value == '--')
&#123;
alert('nothing selected');
return false;
&#125;
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Thx Feyd...

:)
Post Reply