Page 1 of 1

Racking My Brain!

Posted: Thu Jun 18, 2009 8:45 am
by funkymeerkat
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi, could someone help me out here. Probably really simple but not working.

I am using a javascript validation script on an asp(!!!) page for work. Forgetting the Asp side of things (it works on other pages) when i submit it should ask me to fill out the required fields if not done so.

Its fins on the text fields but the drop down menus just are not "requiring" an entry to be chosen....

Script

Code: Select all

<script>
 
function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("One or more of the required fields are not completed. Please complete them, then submit again!")
return false
}
else
return true
}
</script>
Part of page having the problem...

Code: Select all

    <select name="requiredFunctional" accesskey="7" tabindex="7">
                    <option selected>Select One</option>
        <option value="Customer Service">Customer Service</option>
                    <option value="Finance">Finance</option>
                    <option value="Human Resources">Human Resources</option>
                    <option value="Information Technology">Information Technology</option>
                    <option value="Manufacturing">Manufacturing</option>
                    <option value="Operations">Operations</option>
                    <option value="Procurement">Procurement</option>
                    <option value="R&D">R&D</option>
                    <option value="Sales">Sales</option>
                  </select>
If you leave the field as it is, selected on "select one", it submits fine with empty field. Not what i want.

Any ideas?


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Racking My Brain!

Posted: Fri Jun 19, 2009 9:22 am
by Loki
Have you tried setting the value of "Select One" specifically to NULL, or value=""?

Re: Racking My Brain!

Posted: Fri Jun 19, 2009 9:58 am
by funkymeerkat
Yep tried both - no joy....a right pain in the ....

Re: Racking My Brain!

Posted: Fri Jun 19, 2009 10:09 am
by pickle
Have you tried just checking the value of the <select>, rather than doing all that fancy logic to determine if it's a <select> in the first place?

Re: Racking My Brain!

Posted: Sun Jun 21, 2009 8:59 am
by NatalieM
On line 9, shouldn't you check that the selectedIndex = 0 (ie your first option, which is the "select one" option tag), instead of = -1?