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:
  #1  
Old September 28th, 2004, 05:37 PM
mikeparis mikeparis is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: St.Catharines, Ontario
Posts: 47 mikeparis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Checking required fields in javascript...

Hi there, I'd like to add support to this function in the form of checking "select" fields.

Currently, this code looks to see if an input tag has the id "required" and tests for a zero length.

I've tried adding the "select" inputs into the conditional statement, to no avail.

Can someone give me a hand to sort this out?

Thanks.

Here's the code (I will try to get it smaller)

Code:
		function checkrequired(which){
		var pass=true
		if (document.images){
			for (i=0;i<which.length;i++){
				var tempobj=which.elements[i]
				if (tempobj.id=="required"){
					if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charA  t(0)=="s"&&tempobj.selectedIndex==-1)){			
						pass=false
						break
					}
				}
			}
		}

Reply With Quote
  #2  
Old September 28th, 2004, 07:12 PM
brut brut is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 367 brut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 30 sec
Reputation Power: 2
RE: Checking required fields in javascript...

As long as you have 'Select one...' or somesuch as your first option, just change your '-1' to '0'.
And add one more closing brace.

Reply With Quote
  #3  
Old September 28th, 2004, 07:32 PM
mikeparis mikeparis is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: St.Catharines, Ontario
Posts: 47 mikeparis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: RE: Checking required fields in javascript...


Quote:
As long as you have 'Select one...' or somesuch as your first option, just change your '-1' to '0'.
And add one more closing brace.


Sorry could you clarify that for me please.

I'm not very proficient with javascript, I am under the impression that I'll need to create some code like this:

Code:
if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="select")&&tempobj.value=='')||(tempobj.type.toString().charA  t(0)=="s"&&tempobj.selectedIndex==0)){ 


Is this what you describe?

My first option in the html code is along the lines of "Select Option" and has a value of '', for example:

<select name="selectInput">
<option value=''>Select an Option</option>
<option value="option1">OPTION 1</option>
<option value="option2">OPTION 2</option>
</select>

Theoretically, I want the function to return the var 'pass' as false if option 1 or option 2 are not selected.

Thanks in advance for lending a hand.

Reply With Quote
  #4  
Old December 14th, 2005, 02:45 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Checking required fields in javascript...


Quote:
Hi there, I'd like to add support to this function in the form of checking "select" fields.

Currently, this code looks to see if an input tag has the id "required" and tests for a zero length.

I've tried adding the "select" inputs into the conditional statement, to no avail.

Can someone give me a hand to sort this out?

Thanks.

Here's the code (I will try to get it smaller)

Code:
		function checkrequired(which){
		var pass=true
		if (document.images){
			for (i=0;i<which.length;i++){
				var tempobj=which.elements[i]
				if (tempobj.id=="required"){
					if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charA  t(0)=="s"&&tempobj.selectedIndex==-1)){			
						pass=false
						break
					}
				}
			}
		}


Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Checking required fields in javascript...


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 5 hosted by Hostway
Stay green...Green IT