Rodrigo Kx Posted October 20, 2011 Report Share Posted October 20, 2011 (edited) Fala glr..Tenho vários campos 'checkbox' com os mesmos nomes sendo name=var[]Quero fazer um validação para que se nenhuma opção for selecionada ele retorna um alert.Obrigado desde já. Edited October 21, 2011 by Rodrigo Kx Quote Link to comment Share on other sites More sharing options...
0 Tenko Posted October 20, 2011 Report Share Posted October 20, 2011 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>teste</title><script>function valida(){ var controle = 0; var elementos = document.getElementsByName('var[]'); for(var i = 0; i < elementos.length; i++){ if( elementos.checked ) controle++; } if( controle == 0 ) alert('Selecione pelo menos um'); else alert('OK');}</script></head><body><table width="100%" border="1"> <tr> <td><input type="checkbox" name="var[]" value="1"></td> <td>1</td> </tr> <tr> <td><input type="checkbox" name="var[]" value="2"></td> <td>2</td> </tr> <tr> <td><input type="checkbox" name="var[]" value="3"></td> <td>3</td> </tr> <tr> <td width="4%"> <input type="checkbox" name="var[]" value="4"></td> <td width="96%">4</td> </tr></table><br/><br/> <input type="button" name="Button" value="Gravar" onClick="valida()"></body></html> Quote Link to comment Share on other sites More sharing options...
0 Rodrigo Kx Posted October 21, 2011 Author Report Share Posted October 21, 2011 TenkoIsso mesmo cara, Obrigado!! Quote Link to comment Share on other sites More sharing options...
Question
Rodrigo Kx
Fala glr..
Tenho vários campos 'checkbox' com os mesmos nomes sendo name=var[]
Quero fazer um validação para que se nenhuma opção for selecionada ele retorna um alert.
Obrigado desde já.
Edited by Rodrigo KxLink to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.