Make a form for data entry. On the form will be at the following information: name, address and registration number.
Add validation controls on the form, so that the user can only enter the appropriate data (name and surname only letters in the mail just mail in the registration number of digits only).
If you're not using jQuery (which you don't need for something like this), then each form element would be referred to by document.forms["formname"].elementName. Depending upon what kind of element it is (input text, input radio, input checkbox, select, textarea, etc.) the value can be referenced in different ways.
Input text or textarea: document.forms["formname"].textInputID.value.
Input radio/checkbox: document.forms["formname"].inputID[index] where index is the zero-based position of which element is checked.
Select: document.forms["formname"].selectID.value or document.forms["formname"].selectID.selectedIndex to get the position of the selected option.
For text and textarea, you can't just check for a blank value "", because even just one space (and just a space) will bypass the validation. You can use RegEx, but I suspect that you aren't familiar with it. Best to use prototype to give the JS a trim function:
Code:
if(!String.prototype.trim){ String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/,''); } }
if(document.forms"formname"]textInputID.value.trim() == "") // Trim the value and check for anything.. if not, it's not valid
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
If you're not using jQuery (which you don't need for something like this), then each form element would be referred to by document.forms["formname"].elementName.
That's the prehistoric way of doing it. Since each form field needs an id to attach its label you may as well reference them using document.getElementById just as for any element with an id.
@Wolfshade your regex for the trim requires the global modifier (g) to remove spaces at the end of the text as well as the beginning:
Code:
return this.replace(/^\s+|\s+$/g,'')
I like my/this version which behaves like Excel's TRIM function; that is, collapsing spaces between words:
Code:
if (!String.prototype.trim) {
String.prototype.trim = function () {
var s = this.replace(/^\s+|\s+$/g,"");
return s.replace(/\s+/g," ");
}
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
@Wolfshade your regex for the trim requires the global modifier (g) to remove spaces at the end of the text as well as the beginning:
Code:
return this.replace(/^\s+|\s+$/g,'')
Not to hijack the thread, but why use the global flag if I'm using ^ and $ ? I thought by explicitly stating /^ start of string, and $/ end of string, that would replace all beginning and ending whitespace with nothing.
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
Not to hijack the thread, but why use the global flag if I'm using ^ and $ ? I thought by explicitly stating /^ start of string, and $/ end of string, that would replace all beginning and ending whitespace with nothing.
Without the g-global modifer it will replace spaces either at the beginning or the end, but not both. That is, if the spaces are at the beginning, it will replace these but not continue to examine the rest of the string. The pipe separator | means or. The global modifier means "don't stop!".
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
They're never gonna learn everything if you guys are this kind... I'd take a leaf out of devnull's book XDXD
Not only that, but surely you could be charging money for what is essentially him asking you to do a coding task for him, not spot the errors?
meh i dunno... I've only been here two days!
We haven't provided the full code that the OP was seeking and he won't be able to make use of the information we have provided (during our discussion) without putting in a substantial effort himself.
Personally, I rarely supply full code unless I can see that the OP is putting in (or has made..) some effort (usually over the course of a few posts) and/or it is something that interests me
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Make a form for data entry. On the form will be at the following information: name, address and registration number.
Add validation controls on the form, so that the user can only enter the appropriate data (name and surname only letters in the mail just mail in the registration number of digits only).
Thanxxxxx
Form validation has been covered very many times in this forum. Have you tried using the search feature?
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.