iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
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

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-06-2006, 05:01 PM
WebProWorld Member
 
Join Date: Jan 2006
Location: Ireland
Posts: 52
jasonweb RepRank 0
Default Problem with form validation

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.
Reply With Quote
  #2 (permalink)  
Old 03-07-2006, 05:12 PM
WebProWorld New Member
 
Join Date: Sep 2005
Posts: 15
webmaster@pinecone.com RepRank 0
Default

can you post the form code so we can see how you've defined your form?

Thanks
Reply With Quote
  #3 (permalink)  
Old 03-07-2006, 05:55 PM
compusolver's Avatar
WebProWorld Member
 
Join Date: Sep 2003
Location: Oklahoma
Posts: 80
compusolver RepRank 0
Default

Code:
function checkjobtype() { 
  if(document.myForm.JOBTYPE.value=="") { 
    return false;
  } else { 
    return true;
  } 
}
Remember, function names, form names, field names - nearly everything in JavaScript is case-sensitive. Your function (above) looks OK.

If your form tag includes this:
Code:
onSubmit = 'return checkjobtype()'
then the user should stay on that page until the form is cleared to be submitted (passes this function).

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;
}
[Called with: changed(selectObjName)]
__________________
- Hank Castello
www.CompuSolver.com
www.SmBizHosting.com
Hosting, eCommerce Gateways & affordable subcontract programming/consulting
Reply With Quote
  #4 (permalink)  
Old 03-07-2006, 09:49 PM
DrTandem1's Avatar
WebProWorld 1,000+ Club
 
Join Date: Oct 2003
Location: Encinitas, CA
Posts: 1,830
DrTandem1 RepRank 2
Default

Just curious, why did you decide to use JavaScript rather than PHP?
__________________
DrTandem's San Diego Web Page Design, drtandem.com
Reply With Quote
  #5 (permalink)  
Old 03-08-2006, 05:31 AM
pagetta's Avatar
WebProWorld Veteran
 
Join Date: Nov 2004
Location: UK
Posts: 509
pagetta RepRank 2
Default

I have a similar thing and this is how I do it:

have this as your first option value
<option value="None">Please Select... </option>

and in your javascript have this
if (document.myForm.JOBTYPE.value=="None") {
return false;
} else {
return true;
}

hope that helps
Reply With Quote
  #6 (permalink)  
Old 03-08-2006, 05:34 AM
pagetta's Avatar
WebProWorld Veteran
 
Join Date: Nov 2004
Location: UK
Posts: 509
pagetta RepRank 2
Default

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
Reply With Quote
  #7 (permalink)  
Old 03-08-2006, 06:00 AM
WebProWorld Pro
 
Join Date: Mar 2004
Location: Bonnie Scotland
Posts: 103
colr RepRank 0
Default

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__
__________________
Colin Reid
East Kilbride
Reply With Quote
  #8 (permalink)  
Old 03-08-2006, 11:51 AM
WebProWorld Member
 
Join Date: Jan 2006
Location: Ireland
Posts: 52
jasonweb RepRank 0
Default Thanks for the help thus far

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?
Reply With Quote
  #9 (permalink)  
Old 03-08-2006, 12:48 PM
WebProWorld Member
 
Join Date: Jan 2006
Location: Ireland
Posts: 52
jasonweb RepRank 0
Default Just tried and it didn't work

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;
}
Reply With Quote
  #10 (permalink)  
Old 03-09-2006, 02:16 AM
DrTandem1's Avatar
WebProWorld 1,000+ Club
 
Join Date: Oct 2003
Location: Encinitas, CA
Posts: 1,830
DrTandem1 RepRank 2
Default

Quote:
Originally Posted by colr
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__
My thought on this is why rely on the client-side to validate? Also, different browsers have different reactions to validation. If you use your own server-side, then the results are consistent for both you and the visitor. You can make your error page the same as your form page, so they can see what they are missing without using a different page, if that is an issue.
__________________
DrTandem's San Diego Web Page Design, drtandem.com
Reply With Quote
  #11 (permalink)  
Old 03-09-2006, 03:28 AM
southplatte's Avatar
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Colorado
Posts: 358
southplatte RepRank 1
Default

Quote:
Originally Posted by DrTandem1
Quote:
Originally Posted by colr
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__
My thought on this is why rely on the client-side to validate? Also, different browsers have different reactions to validation. If you use your own server-side, then the results are consistent for both you and the visitor. You can make your error page the same as your form page, so they can see what they are missing without using a different page, if that is an issue.
DrTandem1: I think the point that was being gotten to here was the fact that if you perform all the basic validation at the client level, in this case using javascript which most any decent browser supports now, and most users leave functional, you cut down the server load. Many people don't have a problem there, but what if you had a page getting 100,000 hits a day, and that page was your form page, and it was filled out 50% of that 100,000? That would be a very server intensive form script that could save alot of bandwidth and server overhead if the client validated the basics of it, then passed it to PHP or ASP server scripts to final validate it for anything futher and prepare it for the database or file writes that are likely.

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.
Reply With Quote
  #12 (permalink)  
Old 03-09-2006, 07:50 AM
WebProWorld Member
 
Join Date: Jan 2006
Location: Ireland
Posts: 52
jasonweb RepRank 0
Default Still Working on it

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:
Originally Posted by colr
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.
colr__
Reply With Quote
  #13 (permalink)  
Old 03-10-2006, 12:22 PM
DrTandem1's Avatar
WebProWorld 1,000+ Club
 
Join Date: Oct 2003
Location: Encinitas, CA
Posts: 1,830
DrTandem1 RepRank 2
Default

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
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:47 AM.



Search Engine Optimization by vBSEO 3.3.0