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.
Script: - <SCRIPT type=text/javascript>
-
-
/*
-
Navigate to specific plan code web page
-
*/
-
-
-
function getURL(val){
-
base = 'http://dhpulse.hosp.dhha.org/EducationTraining/DH_Revenue_Ed/DH_Rev_Ed_Resources/Ins%20Gadget/PlanCards/';
-
location = base + val + '.htm';
-
return false;
-
}
-
-
</SCRIPT>
Form that collects input: - <FORM id=form2 name=form2 onsubmit="return getURL(this.url.value)" action=""
-
method=post>Enter a Plan Code<BR>
-
<LABEL><INPUT size=3 name=url> </LABEL>
-
<LABEL><INPUT type=submit value=GO name=Submit> </LABEL>
-
</FORM>
Thanks for any help,
5 2958
Declare an array:
then loop over it to compare with the url (passed value). If it doesn't match, return false.
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... -
function getURL(val){
-
if( ! ({ A33:1, B33:1, A80:1, B22:1 })[ val ] ){
-
alert("not a valid val");
-
return;
-
}
-
base = 'http://dhpulse.hosp.dhha.org/EducationTraining/DH_Revenue_Ed/DH_Rev_Ed_Resources/Ins%20Gadget/PlanCards/';
-
location = base + val + '.htm';
-
return false;
-
}
-
-
-
A33, B33, A80, B22
-
-
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.
@cstansbu
if that's the case, simply do it once in the object value matcher: -
-
function getURL(val){
-
if( ! ({ A33:1, B33:1, A80:1, B22:1 })[ String(val).toUpperCase() ] ){
-
alert("not a valid val");
-
return;
-
}
-
base = 'http://dhpulse.hosp.dhha.org/EducationTraining/DH_Revenue_Ed/DH_Rev_Ed_Resources/Ins%20Gadget/PlanCards/';
-
location = base + val + '.htm';
-
return false;
-
}
-
-
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.
Perfect. I was trying to put the toUppercase before the If 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 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: 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:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
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: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
| |