|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
}
}
}
}
|
|
#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. |
|
#3
|
|||
|
|||
|
RE: RE: Checking required fields in javascript...
Quote:
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. |
|
#4
|
|||
|
|||
|
RE: Checking required fields in javascript...
Quote:
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Checking required fields in javascript... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|