0

The problem I am having is that it is out putting employee number not valid while I am typing a valid ID.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">
<!--



var emp = new Array ("Billy", "Jill", "Wolfgang", "Xavier", "Antoinette","John")
var empNum = new Array (78,90,23,12,56,31)

var i = 0


 
var empSearch = eval(prompt("Please Enter the ID of the employee you are looking for?"));

for(var i = 0; i < empNum.length; i++)
{

 
 if (empNum[i] == empSearch)
 {
 document.write("<br> employee number is valid, this employee is " + emp[i] + "<br>")
 }
   
   else 
   {
   document.write("employee number is not valid")
   }

}
//-->
</SCRIPT>


</BODY>
</HTML>

Edited by ALorenzo91: n/a

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by ALorenzo91
0

try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!--
var emp = new Array ("Billy", "Jill", "Wolfgang", "Xavier", "Antoinette","John")
var empNum = new Array (78,90,23,12,56,31)
var i = 0
var empSearch = eval(prompt("Please Enter the ID of the employee you are looking for?"));
for(var i = 0; i < empNum.length; i++)
{

 if (empNum[i] == empSearch)
 {
   document.write("<br> employee number is valid; this employee is " + emp[i] + "<br>");
   break;
 }
 else
 {
 	//document.write("employee number is not valid");
 }
}
//-->
</SCRIPT>
</BODY>
</HTML>
0

That was the solution I was considering but I need an error message if the ID is not valid.

0

try this is working:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!--
var emp = new Array ("Billy", "Jill", "Wolfgang", "Xavier", "Antoinette","John")
var empNum = new Array (78,90,23,12,56,31)

var i = 0

 var empSearch = eval(prompt("Please Enter the ID of the employee you are looking for?"));
smsg="";
emsg="";
for(var i = 0; i < empNum.length; i++)
{
if (empSearch!=null && empSearch!="")
 {

 if (empNum[i] == empSearch)
 {
   smsg="<br> employee number is valid; this employee is " + emp[i] + "<br>";
   break;
 }
 else
 {
 	emsg="employee number is not valid";
 }
  }
   
}

if(smsg!="")
document.write(smsg);
else
document.write(emsg);
//-->
</SCRIPT>


</BODY>
</HTML>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.