SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: select input validator
-
Jul 27, 2007, 01:06 #1
- Join Date
- Jun 2002
- Location
- Buenos Aires, Argentina
- Posts
- 361
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
select input validator
While this code works allright for text-inputs validation, It doesnt work for "select" types.
Code:if (document.nueva.pricing.value == '' ) { alert('El campo `pricing´ es obligatorio.'); nueva.pricing.focus(); error_de_validacion = 'S'; return(false); }
My SOHO: http://www.contactopuro.com.ar
-
Jul 27, 2007, 01:55 #2
- Join Date
- Oct 2004
- Location
- Birtley, UK
- Posts
- 2,439
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
When accessing elements with an ID its best using document.getElementById
ie
Code:if (document.getElementById('pricing').value == '' ) { alert('El campo `pricing´ es obligatorio.'); nueva.pricing.focus(); error_de_validacion = 'S'; return(false); }
I tend to add a 'Please Select' option, and check if that has or hasn't been selected, Usually the selectedIndex should be more than 0 (if you have the please select option)
Bookmarks