javascriptuser1
11-19-2003, 05:10 AM
hi all,
i have to validate the drop down menu.if user select civilid menu drop down then i should validate
1)user shuld enter civlild in text field
2)it should not be less than 12 numbers and should not be greater than 12 numbers
till now everthing is fine
for me 1 and 2 is working fine.
if user selects passport or driving licence from drop down there should be any validation and this is not working.
i mean when the user select passport or driving licence it still alerting me enter 12 number only.
how to overcome this small problem.
here is my code.
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var menu_selection="";
function checkForm() {
if (dropDownMenu() && checktext()) {
alert("\nForm has been filled out correctly.");
}
}
function dropDownMenu(form) {
var myindex=document.forms[0].menu.selectedIndex;
if (myindex==0) {
alert("\nYou must make a selection from the drop-down menu.");
document.forms[0].menu.focus();
}
else {
menu_selection=document.forms[0].menu.options[myindex].value;
alert (menu_selection);
return true;
}
}
function checktext()
{
if (document.forms[0].menu.selectedIndex==1)
{
alert("please enter civild id ");
document.forms[0].civilid.focus();
return false;
}
else if ((document.forms[0].menu.selectedIndex==1) && (document.forms[0].civilid.value.length >12) || (document.forms[0].civilid.value.length <12))
{
alert("enter 12 Number only");
document.forms[0].civilid.focus();
return false;
}
else if (isNaN(document.forms[0].civilid.value))
{
alert("Please insert numeric only");
document.forms[0].civilid.focus();
return false;
}
}
</SCRIPT>
<BODY>
<CENTER>
<FORM>
<TABLE WIDTH=500>
<TR>
<TD><SELECT NAME="menu" SIZE=1>
<OPTION SELECTED VALUE=""> --- select ---
<OPTION VALUE="civilid">civildid </option>
<OPTION VALUE="passport">passport </option>
<option value="Driving licence">Driving licence</option>
</SELECT>
</TR>
<tr>
<td><input type="text" name="civilid"></td>
</tr>
</TABLE>
<TABLE>
<TD align="center"><INPUT TYPE="button" VALUE="Check" onClick="checkForm()">
</TABLE>
<table>
</FORM>
</CENTER>:confused:
i have to validate the drop down menu.if user select civilid menu drop down then i should validate
1)user shuld enter civlild in text field
2)it should not be less than 12 numbers and should not be greater than 12 numbers
till now everthing is fine
for me 1 and 2 is working fine.
if user selects passport or driving licence from drop down there should be any validation and this is not working.
i mean when the user select passport or driving licence it still alerting me enter 12 number only.
how to overcome this small problem.
here is my code.
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var menu_selection="";
function checkForm() {
if (dropDownMenu() && checktext()) {
alert("\nForm has been filled out correctly.");
}
}
function dropDownMenu(form) {
var myindex=document.forms[0].menu.selectedIndex;
if (myindex==0) {
alert("\nYou must make a selection from the drop-down menu.");
document.forms[0].menu.focus();
}
else {
menu_selection=document.forms[0].menu.options[myindex].value;
alert (menu_selection);
return true;
}
}
function checktext()
{
if (document.forms[0].menu.selectedIndex==1)
{
alert("please enter civild id ");
document.forms[0].civilid.focus();
return false;
}
else if ((document.forms[0].menu.selectedIndex==1) && (document.forms[0].civilid.value.length >12) || (document.forms[0].civilid.value.length <12))
{
alert("enter 12 Number only");
document.forms[0].civilid.focus();
return false;
}
else if (isNaN(document.forms[0].civilid.value))
{
alert("Please insert numeric only");
document.forms[0].civilid.focus();
return false;
}
}
</SCRIPT>
<BODY>
<CENTER>
<FORM>
<TABLE WIDTH=500>
<TR>
<TD><SELECT NAME="menu" SIZE=1>
<OPTION SELECTED VALUE=""> --- select ---
<OPTION VALUE="civilid">civildid </option>
<OPTION VALUE="passport">passport </option>
<option value="Driving licence">Driving licence</option>
</SELECT>
</TR>
<tr>
<td><input type="text" name="civilid"></td>
</tr>
</TABLE>
<TABLE>
<TD align="center"><INPUT TYPE="button" VALUE="Check" onClick="checkForm()">
</TABLE>
<table>
</FORM>
</CENTER>:confused: