|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
The last part of the form validation I'm working on is not reading a field when its being entered by a user. Basically Im using javascript to validate the form on the client side and when the user fills in the field whick is a drop drop box the form is still telling them its empty. I think I may have missed a bracket somewhere along the line, here is the script;
function checkjobtype() { if(document.myForm.JOBTYPE.value=="") { return false;} else { return true;} } The other problem I'm having is that after clicking throught the alert boxes the action brings you to the page that says the page has been processed. Is there away to keep the user on the form page after they have clicked submit if they have not entered information into required fields. I know its a big ask but any help would be much appreciated. |
|
||||
|
Code:
function checkjobtype() {
if(document.myForm.JOBTYPE.value=="") {
return false;
} else {
return true;
}
}
If your form tag includes this: Code:
onSubmit = 'return checkjobtype()' Note that if JOBTYPE is a <select> tag, then you have to test its value altogether differently: Code:
function changed(mnu) {
selectedOptionValue = mnu.options[mnu.selectedIndex].value;
selectedOptionText = mnu.options[mnu.selectedIndex].text;
}
__________________
- Hank Castello www.CompuSolver.com www.SmBizHosting.com Hosting, eCommerce Gateways & affordable subcontract programming/consulting |
|
||||
|
just to note - on more recent forms I use php to ensure all necessary fields are filled in, but on these using javascript, instead of just a 'return false;' I use an alert box so as the user knows what field they have missed, eg:
if (d.fieldname.value == "None") { alert( "Please fill in xxx box"); d.know.focus(); return false; } helps the user if its a long form. but I have found php to be quicker |
|
|||
|
Make sure you have the value set in the select list options. If you dont explicitly say value="theval", then it will always appear empty in your javascipt.
DrTandem1 >> does it not make sense to do client validation first to catch any obvious errors? That way they dont need to make any server requests just to validate that their input is wrong. Validate on both the client and the server for a complete, secure, and customer-friendly site. colr__ |
|
|||
|
I'm using javascript as we never learnt PHP in college, is it hard to learn?
Thanks for your help people. I will probably use compusolver's suggestion as it should work with Job Type being the last field needed. Thanks pagetta I am using Alert Boxes for each of the seven required fields. I read about the fact that you should use server side validation aswell as the client side script I have started writing. How do I impliment this and can I just copy and paste the client side script, or what changes do I need to make. Sorry for all the questions but this is the first form I have put online. Do I need to access my ASP bin on my server to read any enquires I have received or can I make that script on the server send it to an email address? |
|
|||
|
I just tried it your way compusolver and your right it stops me from going to the validated page but even now when the form is filled out correctly it doesn't allow me to to see the form validated page, and it has also stopped popping up the alert boxes.
When I used the normal method to check a previous <SELECT> field it did pop up an alert box if it wasn't filled in correctly so do I need to use this? Code:
function changed(mnu) {
selectedOptionValue = mnu.options[mnu.selectedIndex].value;
selectedOptionText = mnu.options[mnu.selectedIndex].text;
}
|
|
||||
|
Quote:
__________________
DrTandem's San Diego Web Page Design, drtandem.com |
|
||||
|
Quote:
The other problem is many people still do not do separate database abstraction layers in the web apps at a more basic level, and thus may inadvertantly execute a SQL query each time this page loads running the server-side code, where as if the client-side checks do not pass, that query would not run. It would only run when the javascript passed all the variables over to the server-side script. I still suggest put all the database sql stuff in it's own abstract layer and interface to run it only when all is said and done, but not everyone sees it that way. Jason, PHP is easy to learn, but if you are using windows based hosting with ASP you should use that, or change hosts to one that supports PHP. Sure PHP will run on windows, but I prefer it on in a linux environment with apache and mysql. ASP supports VBScript and JScript if I am not mistaken, but I do not use it so do not hold me to that one. There are some great ASP people on here that could help you more than me, but I can sure point you in the direction of some great PHP info. |
|
|||
|
I'm not sure how you mean by making sure that I have the value set. At the moment I am just using "" for none when nothing is selected. Surely Javascrpit validation will know that this is empty as it did with another select field further up the form. If I put in "Select Job Type" as the default could I say that if this is left selcted that the field is in error as notrhing has been selected?
Also how do I pass this information onto a database or email address, anyone know any good tutorials sites for this. THanks for the Help Doctor. J [quote="DrTandem1"] Quote:
|
|
||||
|
If you have a page that is taking in 100,000 hits a day, you can afford more server power. If the form is only being correctly completed 50% of the time, then there is an issue with how the form is designed.
My thoughts on browser compatibility was not that they don't support form validation via JavaScript. My point was that different browsers interpret the validation process differently. Some will give pop-up windows that will mystify the visitor. I still think it is better to control the validation process uniformly using the server-side.
__________________
DrTandem's San Diego Web Page Design, drtandem.com |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |