473,232 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

Validate user entry against array for getURL

This is the item selection piece for a Sharepoint knowledge base. If you type a valid plan code you get info, but if you type garbage you get a 404 file not found. I want to check user input against an array of allowable values (eg. A33, B33, A80, B22, etc...) .

true = go to the topic you put in; false = go to a form similar to the original but alerting you to invalid entry.

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT type=text/javascript>
  3. /* 
  4. Navigate to  specific plan code web page
  5. */
  8. function getURL(val){
  9. base = 'http://dhpulse.hosp.dhha.org/EducationTraining/DH_Revenue_Ed/DH_Rev_Ed_Resources/Ins%20Gadget/PlanCards/';
  10. location = base + val + '.htm';
  11. return false;
  12. }
  14. </SCRIPT>

Form that collects input:

Expand|Select|Wrap|Line Numbers
  1. <FORM id=form2 name=form2 onsubmit="return getURL(this.url.value)" action="" 
  2. method=post>Enter a Plan Code<BR>
  3. <LABEL><INPUT size=3 name=url> </LABEL>
  4. <LABEL><INPUT type=submit value=GO name=Submit> </LABEL>
  5. </FORM>
Thanks for any help,
Jan 29 '09 #1
5 2955
16,027 Expert Mod 8TB
Declare an array:
Expand|Select|Wrap|Line Numbers
  1. var array = ["A33",...];
then loop over it to compare with the url (passed value). If it doesn't match, return false.
Jan 30 '09 #2
rnd me
427 Expert 256MB
you can avoid the loop by using an object to specify ok values.
this also avoids multiple comparisons, so it should be faster in theory, though i doubt for something small like this it matters much.

still, it's a handy pattern that's fast and avoids more complicated branching and comparing.

add any others in the same format (xx:1,) to customize...

Expand|Select|Wrap|Line Numbers
  1. function getURL(val){
  2.   if( ! ({ A33:1, B33:1, A80:1, B22:1 })[ val ]  ){ 
  3.     alert("not a valid val");
  4.     return;
  5.   }
  6. base = 'http://dhpulse.hosp.dhha.org/EducationTraining/DH_Revenue_Ed/DH_Rev_Ed_Resources/Ins%20Gadget/PlanCards/';
  7. location = base + val + '.htm';
  8. return false;
  9. }
  12. A33, B33, A80, B22
Jan 31 '09 #3
Thanks for both! I'm learning, so its very good to see both approaches. I see now that to polish it off, I'll either need to check for A33, a33, B33, b33, etc... or convert the case of the user input.
Jan 31 '09 #4
rnd me
427 Expert 256MB
if that's the case, simply do it once in the object value matcher:

Expand|Select|Wrap|Line Numbers
  2. function getURL(val){
  3.    if( ! ({ A33:1, B33:1, A80:1, B22:1 })[ String(val).toUpperCase() ]  ){ 
  4.      alert("not a valid val");
  5.      return;
  6.    }
  7.  base = 'http://dhpulse.hosp.dhha.org/EducationTraining/DH_Revenue_Ed/DH_Rev_Ed_Resources/Ins%20Gadget/PlanCards/';
  8.  location = base + val + '.htm';
  9.  return false;
  10.  }
notice how a string is created for safety, then the string is converted to uppercase for the comparison.

now you only need to code upper case versions.
Jan 31 '09 #5
Perfect. I was trying to put the toUppercase before the If
Jan 31 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

by: lawrence | last post by:
I'm running this page: http://www.krubner.com/rss/page938.xml through this validator: http://rss.scripting.com/?url=http%3A%2F%2Fwww.krubner.com%2Frss%2Fpage938.xml
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a...
by: LesleyW | last post by:
Hi Apologies if this is a really dumb question, but being new to XML and Schemas, I wonder if giving the namespace for eg xsd or xsi as a website address means that the user has to be online...
by: Ali-R | last post by:
Hi all, I am getting a CSV file like this from our client: "C1","2","12344","Mr","John","Chan","05/07/1976"......... I need to validate **each filed value** against a set of rules ,for...
by: Wysiwyg | last post by:
I need to validate a form to ensure that all of the fields add up correctly. I can't do this while the user is entering data since validation needs to be done after the entry is completed. What's...
by: windandwaves | last post by:
Hi Folk, I use AJAX to load some XML. When I get back to XML, I want to get a piece of html that is within <info>... lots of html .... </info> I want to use: ...
by: anilareddy | last post by:
I have an application like this. I need to validate the start time in 2nd row against the start row in first row. I mean The start time value entered in the second row must not b the value entered in...
by: =?Utf-8?B?SGFycnkgVg==?= | last post by:
Is it possible to validate a 2-character substring against a list of 13 2-character codes without a select statement to a table or parsing an array? Something like ... myChars in ("aa", "bb",...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.