Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old January 24th, 2005, 07:41 PM
jweizenblut jweizenblut is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Miami, Fl. US
Posts: 522 jweizenblut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 29 sec
Reputation Power: 2
Send a message via AIM to jweizenblut Send a message via Yahoo to jweizenblut
Form error trapping...

I ahve the following code for error trapping form contents before submission:

<script language="javascript">
function checkform (form) {
if (form["name"].value == "") {
alert("A name must be entered.");
form["name"].focus();
return false ; }
if (form["shift"].value == "") {
alert("A shift must be entered.");
form["shift"].focus();
return false ; }
if (form["location"].option == "CLICK HERE") {
alert("A location must be selected.");
form["location"].focus();
return false ; }
return true; }
</script>

I have 2 problems.
1 - Trying to figure out how to make it so that if under location, which is a form list object, if <option>CLICK HERE</option> is not changed, for the form to give an error message.
2 - Trying to figure out how to make it so that if under location, which is a form list object, if <option>RAMP</option> is selected for it to cross-check and make sure the comment input has text entered.

Any ideas?

Reply With Quote
  #2  
Old January 24th, 2005, 09:45 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Form error trapping...

for #1 you need to use the selectedIndex property of the select object (there is no option property)

it would look like this

if (form["location"].selectedIndex == 0) {
alert("A location must be selected.");
form["location"].focus();
return false;
}
The index starts at zero so if "CLICK HERE" is the first item in the dropdwn then its index is '0'

for # 2 just use an else if to see if the selectedIndex for ramp has been selected, if it has check the value of the comment input area

the whole thing would look like this

if (form["location"].selectedIndex == 0) {
alert("A location must be selected.");
form["location"].focus();
return false;
}else if (form["location"].selectedIndex == 2) {
if (form.["comments"].value == ""){
alert("Please enter a comment");
form.["comment"].focus();
return false;
}
}

replace 2 with the index that correspondes to the "RAMP" option


Reply With Quote
  #3  
Old January 25th, 2005, 07:23 PM
jweizenblut jweizenblut is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Miami, Fl. US
Posts: 522 jweizenblut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 29 sec
Reputation Power: 2
Send a message via AIM to jweizenblut Send a message via Yahoo to jweizenblut
RE: Form error trapping...

The error trapping for the list works if nothing has been selected. Unfortunately, option 2 doesn't work well for me. BElow is the code I have that works right now:

<script language="javascript">
function checkform (form) {
if (form["name"].selectedIndex == 0) {
alert("A name must be selected from the list.");
form["name"].focus();
return false; }
if (form["shift"].value == "") {
alert("A shift must be entered.");
form["shift"].focus();
return false ; }
if (form["location"].selectedIndex == 0) {
alert("A location must be selected from the list.");
form["location"].focus();
return false; }
if (form["type"].selectedIndex == 0) {
alert("A type must be selected from the list.");
form["type"].focus();
return false; }
return true; }
</script>

I need to modify it so that if "type" index is 3, 4 or 5 for it to cross check and make sure something is entered in the comments field. If no entry is made, then focus to the comment after giving the message.

Reply With Quote
  #4  
Old January 25th, 2005, 07:49 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Form error trapping...

use the same principal based on the example I posted

if (form["type"].selectedIndex == 0) {
alert("A type must be selected from the list.");
form["type"].focus();
return false;
}else if ((form["type"].selectedIndex > 2) && (form["type"].selectedIndex < 6)){
if (form.["comments"].value == ""){
alert("Please enter a comment");
form.["comment"].focus();
return false;
}
}


I didnt test it,but it should do what you want it to do



Reply With Quote
  #5  
Old January 25th, 2005, 09:39 PM
jweizenblut jweizenblut is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Miami, Fl. US
Posts: 522 jweizenblut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 29 sec
Reputation Power: 2
Send a message via AIM to jweizenblut Send a message via Yahoo to jweizenblut
RE: Form error trapping...

I have tried using the code you gave me, and changing it, regardles of what I do, it seems that my if conditions get ignored when I add the code. My code before, that works, except for the cross-reference is:
function checkform (form) {
if (form["name"].selectedIndex == 0) {
alert("A name must be selected from the list.");
form["name"].focus();
return false; }
if (form["shift"].value == "") {
alert("A shift must be entered.");
form["shift"].focus();
return false ; }
if (form["location"].selectedIndex == 0) {
alert("A location must be selected from the list.");
form["location"].focus();
return false; }
if (form["type"].selectedIndex == 0) {
alert("A type must be selected from the list.");
form["type"].focus();
return false; }
return true; }

The code that doesn't work is:

function checkform (form) {
if (form["name"].selectedIndex == 0) {
alert("A name must be selected from the list.");
form["name"].focus();
return false; }
if (form["shift"].value == "") {
alert("A shift must be entered.");
form["shift"].focus();
return false ; }
if (form["location"].selectedIndex == 0) {
alert("A location must be selected from the list.");
form["location"].focus();
return false; }
if (form["type"].selectedIndex == 0) {
alert("A type must be selected from the list.");
form["type"].focus();
return false; }
else if ((form["type"].selectedIndex > 2) && (form["type"].selectedIndex < 6)){
if (form.["comments"].value == ""){
alert("Please enter a comment");
form.["comment"].focus();
return false; }
}
return true; }

Once I add the code, none of my conditions work and they get bypassed entirely. Any ideas?

Reply With Quote
  #6  
Old January 25th, 2005, 11:25 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Form error trapping...

as I stated I did not test the code and found errors upon debugging.... the if for the comments should look like this

if (form["comments"].value == ""){
alert("Please enter a comment");
form["comment"].focus();
return false; }

you will notice in the original I posted, there were periods between form and ["comments]

remove them and it should work fine.

I tend to reference form variables differently myself, for the comments field I would use

form.comments.value

instead of form["comments"].value

both do the same thing, but my way takes three less key strokes...lol

Reply With Quote
  #7  
Old January 25th, 2005, 11:58 PM
jweizenblut jweizenblut is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Miami, Fl. US
Posts: 522 jweizenblut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 29 sec
Reputation Power: 2
Send a message via AIM to jweizenblut Send a message via Yahoo to jweizenblut
RE: Form error trapping...

I like your formatting better. And yes, less keystrucks is better.

Unfortunately, this is still not working for me. Now, my previous conditions work, but when I select a value from my type object, it igoners the condition entirely. Here is the code I have now:

function checkform (form) {
if (form.name.selectedIndex == 0) {
alert("A name must be selected from the list.");
form.name.focus();
return false; }
if (form.shift.value == "") {
alert("A shift must be entered.");
form.shift.focus();
return false ; }
if (form.location.selectedIndex == 0) {
alert("A location must be selected from the list.");
form.location.focus();
return false; }
if (form.type.selectedIndex == 0) {
alert("A type must be selected from the list.");
form.type.focus();
return false; }
else if ((form.type.selectedIndex > 2) && (form.type.selectedIndex < 6)){
if (form.comments.value == ""){
alert("Please enter a comment");
form.comment.focus();
return false; }
}
return true; }

Reply With Quote
  #8  
Old January 26th, 2005, 12:02 AM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Form error trapping...

note here you are using two different names

if (form.comments.value == ""){
alert("Please enter a comment");
form.comment.focus();
return false; }


comment & comments

Make sure the proper element names are being referenced I will assume by the fact it is not working, that the name is "comment" but I could be wrong

Reply With Quote
  #9  
Old January 26th, 2005, 05:03 PM
jweizenblut jweizenblut is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Miami, Fl. US
Posts: 522 jweizenblut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 29 sec
Reputation Power: 2
Send a message via AIM to jweizenblut Send a message via Yahoo to jweizenblut
RE: Form error trapping...

Cool. You were right. I guess that after looking at something for plenty of hours, you miss simple mistakes. Sorry about that. Guess there is a reason why they say 2 eyes are better than one.

Thanks!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Form error trapping...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway