473,397 Members | 1,974 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,397 software developers and data experts.

How to validate a specific text field value?

I'd like to ask a question and have the user
type a specific answer into a field. how do I validate
the answer. Any help would be great!

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. function validateForm()
  5. {
  6. var x=document.forms["myForm"]["myText"].value
  7. if (x==null || x=="")
  8.   {
  9.   alert("That is not the correct answer");
  10.   return false;
  11.   }
  12. }
  13. //-->
  14. </script>
Jan 20 '11 #1
5 1751
Dormilich
8,658 Expert Mod 8TB
that depends on how "secret" the answer should be. anything present in JS can be seen by the user.
Jan 20 '11 #2
At this time I'm not real worried about someone being able to find the answer in the source code. Obviously i could tuck it away further in a separate .js file or go server side later. Just looking for assistance on the function. If you could help that would be great.
Jan 20 '11 #3
Dormilich
8,658 Expert Mod 8TB
OK, then, please define "specific answer".
Jan 20 '11 #4
How about "viking".
Jan 20 '11 #5
JKing
1,206 Expert 1GB
Your validation will depend on how strict you want to be with the answer.

I suggest trimming the whitespace, converting the string to all lowercase and then doing a comparisson. This way if they enter "Viking" or "VIKING" or " viking " they will still get the correct answer.

I would save all answers to a database just in case there are any discrepancies.
Jan 20 '11 #6

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

Similar topics

0
by: Pavils Jurjans | last post by:
Hello, I have a third-paty application that uses text type field in MSSQL server to store data of incoming emails (full raw sources, including headers, etc.). Since the emails come in different...
1
by: Arfan | last post by:
I am using fckEditor. I want to get the length of value of the fckeditor text field. Can any1 help me how can i get it through javascript. since when i use alert(texteditorField.value ) it shows...
6
by: isetea | last post by:
Hi, I have two tables with text fields as well as number fields. I try to match the two tables. Sometimes two matched textfields show an unmatch even if there is no value in both fields. Sometimes...
4
by: micatcat | last post by:
Hello, I have a text field that gets populated when the user clicks on the submit button. How do I transfer this field onto a Word document? Please help me.
1
by: gayathri33 | last post by:
I have a text field in JSF,when user enters text,text should be displayed. But onblur (i.e) wen focus moves away from the control, it should be displayed as "***" or "..." ..any one plz help asap...
1
kaleeswaran
by: kaleeswaran | last post by:
hi! now i am validating the field using alert.but instead of using alert method.i would like to alerting the user through changing text colur... how do i do that... give me some idea... ...
7
by: backups2007 | last post by:
I have this javascript validation code that I want to be able to clear an input text box when the inputed value is invalid. Note: this is a reusable validation code. function isChar(form1) {...
3
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in...
2
by: coder10 | last post by:
Hi, Can anyone make me understand in JavaScript what is all which are in bold, I need simple function to validate a text-field on a form that is to hold an email address. The below in bold is...
1
by: madhu sudhanan | last post by:
hey, i need to validate a text field in Visual Basic with alphanumeric of 3 alphabets in the left and three numbers in the right and it should not allow any other special characters,space,backspace...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.