Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

CarlosNet

Validação de checkbox

Recommended Posts

Tenho um formulario onde se você esoclher o status IRREGULAR aparecem algumas opções e você é obrigado a escolher pelo menos uma delas...

 

Acontece que o combo do status e esses checkboxs de irregularidades sao gerados pelo asp apartir de um record set, a linha que gera eles é a seguinte:

 

<TD>						  <SELECT id="cboStatus<%=rsDoc("Cod")%>" name="cboStatus<%=rsDoc("Cod")%>" style="font-family: verdana; font-size: 10px; width: 100px" onChange="Habilita(cboStatus<%=rsDoc("Cod")%>,txtData<%=rsDoc("Cod")%>,div<%=rsDoc("Cod")%>);">							<option value="PENDENTE" <%if rsDoc("Status") = "PENDENTE" then response.write "selected" end if%>>PENDENTE							<option value="OK" <%if rsDoc("Status") = "OK" then response.write "selected" end if%>>OK							<option value="IRREGULAR" <%if rsDoc("Status") = "IRREGULAR" then response.write "selected" end if%>>IRREGULAR						  </SELECT>						</TD>						<TD colspan="2"><INPUT name="txtData<%=rsDoc("Cod")%>"  id="txtData<%=rsDoc("Cod")%>" style="font-family: verdana; font-size: 10px" value="<%if not rsDoc("data") = "01/01/1900" then response.write rsDoc("data") end if%>" size="11" maxlength="10" readonly></TD>					</TR>					<TR style="COLOR: black; font-family: verdana; font-size: 10px"  BGCOLOR=<%=vcor%>>					  <TD colspan="4" bgcolor="WhiteSmoke"><div id="div<%=rsDoc("Cod")%>" style="display : none;"><table width="100%" border="0" align="center" cellpadding="1" cellspacing="1"><%	Set rsOco = server.createobject ("ADODB.Recordset")	rsOco.Open "select * from tbl_AJ_DocumentoOcorrencia where CodDocumento =" & rsDoc("CodDocumento"), Conn	while not rsOco.eof	%>	  <tr>					  		<td valign="middle" class="style2">		<label>		  <input type="checkbox" name="CodDoc<%=rsDoc("Cod")%>" id="CodDoc<%=rsDoc("Cod")%>" value="<%=rsOco("CodOcorrencia")%>" /><%=rsOco("DescOcorrencia")%>		</label>		</td>	  </tr><%	rsOco.movenext	wend	rsOco.Close	Set rsOco = nothing%></table></div></TD>
Sei que é muito chato vcs perderem tempo entendendo o problema, mas eu nao sei mais o que tentar...

Segue abaixo o resultado desse codigo:

 

Imagem Postada

 

Agora não to conseguindo fazer a validação pra que qdo escolher IRREGULAR obrigue o cara a selecionar pelo menos um check box, por favor me deem uma luz !

 

Abraços,

Carlos http://forum.imasters.com.br/public/style_emoticons/default/cry.gif

 

Olha gente eu tentei assim, mas ele envia sem dar o alert, alguem sabe pq ?

armazenei os codigos numa variavel e criei um array...

 

<%			js = "<script>" & vbcrlf			js = js & "function Valida(){" & vbcrlf			arrDoc = split(vDocs,",")			for i = 0 to UBound(arrDoc)						js = js & "if (document.Documento.cboStatus"&Trim(arrDoc(i))&".value == ""IRREGULAR"" && document.Documento.CodDoc"&Trim(arrDoc(i))&".value == "") {" & vbcrlf				js = js & "alert('Selecione uma irregularidade!');" & vbcrlf				js = js & "document.Documento.cboStatus"&Trim(arrDoc(i))&".focus();" & vbcrlf				js = js & "return false;" & vbcrlf				js = js & "}" & vbcrlf			next			js = js & "}" & vbcrlf			js = js & "</script>"			arrDoc = ""			'response.write js			'response.end()		%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

nao sei se entendi direito, mas ve se é mais ou menos como você quer:

function funcao(){ t = document.forms.caixa.length; cont=0;  for(i=0; i < t; i++)   {	if (document.forms.caixa[i].checked)	 cont++;	  if (cont > 1)	  {	   alert("NÃO PODE ENVIAR MAIS QUE UMA!");	  	   return false;	  } 	}   }

chamando:

<form name="forms" action="teste_.html" method="post" onSubmit="return(funcao())">  <p>CAIXAS DE CHECKAGEM:<br>	<input type="checkbox" name="caixa" value="ILEGÍVEL" >	ILEGÍVEL.<br>	<input type="checkbox" name="caixa" value="RASGADO" >	RASGADO. <br>	<input type="checkbox" name="caixa" value="FILTRADO" >	FILTRADO.<br>  </p>  <input type="submit" name="Submit" value="Submit" ></form>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.