Print Page | Close Window

need a simple javascript function

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=25459
Printed Date: 29 March 2026 at 6:50pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: need a simple javascript function
Posted By: iSec
Subject: need a simple javascript function
Date Posted: 17 March 2008 at 8:17pm

Can someone provide me with a function (using javascript) on how to check against a list of items...

example:
 
A user enters a specific value, the script will check against a list of items, if the specified value matches with any of the items in the list then the returned message would be: Welcome
 
If it does not match with the list, the returned value would be: rejected
 
Any help is appreciated.


-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard



Replies:
Posted By: 123Simples
Date Posted: 18 March 2008 at 3:44pm
Do you mean like a

Form Input Validation JavaScript?



-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design


Posted By: iSec
Date Posted: 18 March 2008 at 4:27pm
Yes but not a generic one,.... not like the one that would check to see if as a field was populated with values...
what i'm looking for is a validation script that checks against a list of items as i mentioned above, and depending on the input it will provide different feedback, or direct to a specific page based on the feedback.


-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard


Posted By: 123Simples
Date Posted: 18 March 2008 at 4:46pm
Well I may be on the wrong path here because all my knowledge is self taught (you only have to look at my websites to see that LOL) but, google says:

http://msdn2.microsoft.com/en-us/library/a0z2h4sw(VS.71).aspx which might be what you want


-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design


Posted By: iSec
Date Posted: 18 March 2008 at 5:05pm
That's done in .NET; I need a client-side code (javascript) for this.

-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard


Posted By: 123Simples
Date Posted: 18 March 2008 at 5:21pm
Sorry Info....... See what I mean?
I'd assume though that you would need a database to compare the scripts inputs though, or is not the case?


-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design


Posted By: 123Simples
Date Posted: 18 March 2008 at 5:24pm
What is this for? Home shopping? Database enquiries? Or am I just completely out of my depth?

-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design


Posted By: billd3
Date Posted: 20 March 2008 at 6:52pm
How many items? Many or just a few?
Will this list change or remain static?


-------------
BillD
http://theamcpages.com
http://theamcforum.com


Posted By: iSec
Date Posted: 21 March 2008 at 4:50pm
It's ok... I already got it...
Here is how I did it:
 
  <script language="JavaScript" type="text/javascript">
 function check() {
 
  var items=new Array();
  items[0]="item-1";
  items[1]="item-2";
  items[2]="item-3";
  
  input = document.getElementById("in").value;
  if(input=="") {
   alert("Please enter a value !");
   return;
  }
  
  for(i=0; i<items.length; i++)
   if( input==items ) {
    location.href = "welcome.html";
    return;
   }
  location.href = "rejected.html";
  
 }
  </script>


-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard


Posted By: 123Simples
Date Posted: 21 March 2008 at 6:06pm
I told you I was out of my depth LOL
But it all sounds good anyway

I'm just pleased with myself that I can do what I do with googling and ploughing through bits and bobs, but I will never be up with you guys. I'm too old now to learn that sort of stuff, which is a shame when you have the ideas and hopes, but not the brains Ouch


-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design


Posted By: iSec
Date Posted: 21 March 2008 at 11:23pm
haha...
I'm personally a Information Security guy... that's my major ... I do some basic web design though;  and I'm also involved in the management of a few big web projects like a voice chat that a professional developer and I are doing... my role in that project is financing...testing...etc...


-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard


Posted By: 123Simples
Date Posted: 22 March 2008 at 6:27pm
Sounds like a brain surgeon to me bud, but I'll take your word for it Thumbs%20Up
I run my own businesses, nothing special but it beats working for an employer

I just like learning and challenging myself on the web but I know I will never be up there with the BIG CHEESES! Ermm Geek
But I do like our choices of avatars on our forums compared to the bog standard ones!

At least there I can pull a few more smilies! Big%20smile


-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net