|
IAH (f)
|
Computer gurus, where are you??? Please help a newbie with this. I am trying to make a form for a website. I've finished it but I want to use javascript to validate some required fields before submission of the form. Ok, let me explain better. The form requires a user to fill in stuffs like Name, Email address, etc. But you know some people might not fill certain fields. So if a user tries to submit without filling his name, for example, I want a messagebox/dialogbox to pop up and say "Please enter your name" or something like that. I have tried it but it's not working so please help!!!!!!!! I'm having headache already o!
|
|
|
|
|
|
demmy (m)
|
Here is some code from a javascript book I have. <!-- TWO STEPS TO INSTALL BASIC VALIDATION:
1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin function checkrequired(which) { var pass=true; if (document.images) { for (i=0;i<which.length;i++) { var tempobj=which.elements[i]; if (tempobj.name.substring(0,8)=="required") { if (((tempobj.type=="text"||tempobj.type=="textarea")&& tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&& tempobj.selectedIndex==0)) { pass=false; break; } } } } if (!pass) { shortFieldName=tempobj.name.substring(8,30).toUpperCase(); alert("Please make sure the "+shortFieldName+" field was properly completed."); return false; } else return true; } // End --> </script>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<center> <form onSubmit="return checkrequired(this)">
<input type="text" name="requiredname"> <br> <input type="text" name="requiredemail"> <br> <select name="requiredhobby"> <option selected>Pick an option! <option>1 <option>2 <option>3 </select> <br> <textarea name="requiredcomments"></textarea> <br> <input type=submit value="Submit"> </form> </center>
<!-- The first option in your pulldown menus must be set to 'selected' !! -->
|
|
|
|
|
|
jogego (m)
|
What you are trying to do is more or less validate your user input. I don't use pop ups for this cs most people who are security conscious normally disable pop ups nowadays. For now, I normallly do my scripting in ASP and for data validation my codes go something like:
Function Check Check = False ' Check for Name and password if len(varName) < 1 Then %><title>Sport Club:Wrong details</title>
You must enter a Name<br /> <% Exit Function End if if len(varPassword) < 1 Then %><title> Sport Club:Wrong details</title> You must enter a Password<br /> <% Exit Function End if Check = True End Function
This directs the user to a page displayin the error message. If you need any more help, I'd be glad to assist
|
|
|
|
|
|
IAH (f)
|
Thnaks guys! I'll go try it out and give you feedback on it. 
|
|
|
|
|
|
Seun (m)
|
So there are javascript and ASP gurus on this site. Interesting.
|
|
|
|
|
|
Hunter (m)
|
personally I would see if your host is compatable with PHP as it allows alot more feature rich websites, and there alot of pre written scripts people have written to help get a good website. You can find some good scripts for both java and PHP and several other languages at http://www.hotscripts.com/
|
|
|
|
|
|
modpluz (m)
|
demmy, you mind putting the copyright(that you ripped off) on that javascript code.
|
|
|
|
|
|
demmy (m)
|
Ripped off heh? If you had read my post you would have been informed that I never claimed the code as my own so no need for any "uncovering". As for inserting copyright I don't mind, only the original author never put it there so I never bothered myself either. And for your information I recieved no kobo for that code. I swear.
|
|
|
|
|
|
modpluz (m)
|
demmy, me was just kidding ni oooo. who go pay you for that code(only if they don't know easy it is to get it to work). but you know thats one good part of been a programmer(to you its a piece of cake, but to others...).
|
|
|
|
|
|
sbucareer (m)
|
Another way to accomplish this is to write triggers at your database level. The only downside is that the user is not aware of your application rules until he/she tries to submit the form for processing at the server.
You can get your DBA to writer PL/SQL triggers and other business rules at the DML level. What you do now is to warn the users by putting red * near the field that you want to collect the inforation that this is a required field.
If the user is stupid enough to over look your warning, they will meet their match at the submission part.
NB =========
I was assuming it is a database solution since you are collecting information, possibility is, you will store them. Otherwise why collect inforation?
|
|
|
|
|
|