Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code does not filter by If statement 1

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi,
I have created this small piece of code and the purpose is as follows.

We have several machines and I want to display an alert if the machine number does not equal 1301 OR 1302 AND if the character length in digits in another field is less than 2.

I get the alert irrespective of which machine it is including the 1301 AND 1302

Code:
<script language = "javascript">
// Start PTDREF Script
			function ptd() {
			var msg = "";
			var MC = document.getElementById("hidMCode").value;
			var Print = document.getElementById("txtPrintNo").value.length;
			if (Print <2 && MC!= "1301" || MC!= "1302")msg+="Is This A Printed Reference \nIf So Please Indicate On Form";
  if (msg != "") alert(msg);

  return msg==""
}
// End PTDREF Script
</script>

I wonder if someone can help me please




Regards

Paul

 
Suggest you check the brackets in the IF :

<html>
<head>
<script language="javascript">
// Start PTDREF Script
function ptd()
{
var msg = "";
var MC = document.getElementById("hidMCode").value;
var Print = document.getElementById("txtPrintNo").value.length;
if (Print <2 && (MC!= "1301" || MC!= "1302"))
{
msg+="Is This A Printed Reference \nIf So Please Indicate On Form";
}
if (msg != "")
{
alert(msg);
}

return msg==""
}
// End PTDREF Script
</script>
</head>
<body>
<form>
<input type="text" id="hidMCode">
<input type="text" id="txtPrintNo">
<input type="button" onclick="ptd();">
</form>
</body>
</html?

seems to work for what you have asked for

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Hi Greg,

Thanks for your swift reply, I have changed my code to reflect your suggestions however it does not seem to work for me, I still get the message even if the machine number is 1301 or 1302.

I am going to create another page with the code you sent as I believe that your changes do work, I will then have to figure out why it does not work for me on my existing page

Regards

Paul

 
Test data as follows using my current code:

MC Print Alert shown
1234 1 Y
1234 12 N
1301 12 N
1301 1 Y

reading your reply I think you are after the following :

length of print < 2 chars
AND MC not 1301
AND MC not 1302

Then the if should be :

if (Print <2 && (MC!= "1301" && MC!= "1302"))

This gives the following :

MC Print Alert shown
1234 1 Y
1234 12 N
1301 12 N
1301 1 N

Is that more what you are after ?

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Hi Greg,

Thank you for taking the time to look at this again for me.

The amended code you have given me does exactly what I need.

A "Star" on it's way

[2thumbsup][bigsmile][2thumbsup]

Regards

Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top