feck Posted January 10, 2007 Share Posted January 10, 2007 Do you have to validate selection boxes when validating a form?, seeing as the values entered are restricted too values already placed within the options.If so, could you give me a few pointers in the right direction as to validating these types of inputs. Link to comment Share on other sites More sharing options...
jesh Posted January 10, 2007 Share Posted January 10, 2007 I typically only validate selects that I deem as required by checking to see if the selected index is greater than a default.If your select was: <select id="myselect"> <option value="-1">Select an Option</option> <option value="1">Value 1</option> <option value="2">Value 2</option></select> You could validate that like so: var select = document.getElementById("myselect");if(select.selectedIndex > 0){ // it validates} Or you can validate by value: var select = document.getElementById("myselect");if(select.options[select.selectedIndex].value != "-1"){ // it validates} Link to comment Share on other sites More sharing options...
feck Posted January 11, 2007 Author Share Posted January 11, 2007 thanks jesh,what i'm wondering is say for instance that your putting things into a database, that are preset values like names for instance.You have only four names to choose from do you need to validate these?My question arises because of something I've read about called Javascript Injection whereby a user could actually put in a value to be submitted that is not in the actual selct box. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 11, 2007 Share Posted January 11, 2007 thanks jesh,what i'm wondering is say for instance that your putting things into a database, that are preset values like names for instance.You have only four names to choose from do you need to validate these?My question arises because of something I've read about called Javascript Injection whereby a user could actually put in a value to be submitted that is not in the actual selct box.Could you post the link to that article it would be a good read for everyone. Link to comment Share on other sites More sharing options...
feck Posted January 11, 2007 Author Share Posted January 11, 2007 Here's one I read again todayJavascript Injection Although it does'nt mention anything about select boxes I'm sure the same process applies. Link to comment Share on other sites More sharing options...
Webworldx Posted January 12, 2007 Share Posted January 12, 2007 Ideally you want to be validating all fields server side, the javascript bits are just for end-user experience - so they don't have to keep submitting the form and getting it returned with errors Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now