Mar/097
Combo Dinâmico com AJAX
Default.asp
<html>
<head>
<title>Teste Combo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript" src="ajax.js"></script>
</head>
<body>
Categoria:
<select name="categoria" onchange="alimentarCombo(this.value);">
<option value="">[ Selecione ]</option>
<%
set rs = conn.execute("SELECT codigo, nome FROM categoria ORDER BY nome ASC")
if (not rs.eof) then
while (not rs.eof)
response.write("<option value="""&rs("codigo")&""">"&rs("nome")&"</option>")
rs.moveNext : wend
end if
set rs = nothing
%>
</select>
<br>
Sub-Categoria: <div id="resultado"></div>
</body>
</html>
ajax.js
function GetXMLHttp() {
if (navigator.appName == "Microsoft Internet Explorer") {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
var mod = GetXMLHttp();
function alimentarCombo(valor) {
mod.open("GET", "Carrega.ajax.asp?id="+valor+"", true);
mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
mod.onreadystatechange = function() {
if (mod.readyState == 4) {
document.getElementById("resultado").innerHTML = mod.responseText;
}
};
mod.send(null);
}
Carrega.ajax.asp
<select name="sub_categoria">
<option value="">[ Selecione ]</option>
<%
set rs = conn.execute("SELECT codigo, nome FROM sub_categoria WHERE categoria_id = '"&request.queryString("id")&"'")
if (not rs.eof) then
while (not rs.eof)
response.write("<option value="""&rs("codigo")&""">"&rs("nome")&"</option>")
rs.moveNext :wend
end if
set rs = nothing
%>
</select>
Nov/080
Função “três pontinhos”
Código simples para você ter aqueles "três pontinhos" em sua notícia, feeds etc...
Usando VBScript
<%@ Language="VBScript" %> <% Public Function Pontos(VarTexto, Max) ' Recebemos os valores If Int(Len(VarTexto)) > Max Then Response.Write(Left(VarTexto, Max)&"...") ' Usamos a função "substring" para fazer os cortes Else Response.Write(VarTexto) End If End Function Texto = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the whenwhen, when an unknown printer took a galley of type and scrambled it to make a type specimen book." Call Pontos(Texto, 150) ' Chamando a função e mostrando o resultado %>
Agora usando JScript com ASP
<%@ Language="JScript" %>
<%
function pontos(varTexto, Max) { // Recebemos os valores
if (varTexto.length > Max) {
Response.Write(varTexto.substring(0, Max)+"..."); // Usamos a função "substring" para fazer os cortes
}
else {
Response.Write(varTexto);
}
}
texto = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the whenwhen, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
pontos(texto, 150); // Chamando a função e mostrando o resultado
%>
Jun/084
Retirar Acentos com JavaScript
Esta função simples serve para retirar os acentos do campo, mais ele não retira na hora que você está digitando e sim quando você tira o foco do campo, sendo assim a função é acionada.
aqui abaixo segue o script desenvolvido em javascript retirado da internet e adaptado.
<script language="javascript">
function retirarAcento(objResp) {
var varString = new String(objResp.value);
var stringAcentos = new String('àâêôûãõáéíóúçüÀÂÊÔÛÃÕÁÉÍÓÚÇÜ');
var stringSemAcento = new String('aaeouaoaeioucuAAEOUAOAEIOUCU');
var i = new Number();
var j = new Number();
var cString = new String();
var varRes = '';
for (i = 0; i < varString.length; i++) {
cString = varString.substring(i, i + 1);
for (j = 0; j < stringAcentos.length; j++) {
if (stringAcentos.substring(j, j + 1) == cString){
cString = stringSemAcento.substring(j, j + 1);
}
}
varRes += cString;
}
objResp.value = varRes;
}
</script>
aqui abaixo segue um "form" simples só para teste com o comando "onChange" que contém um javascript para acionar a função "retirarAcento"
<form> <input type="text" name="Teste" onChange="javascript:retirarAcento(this);"> </form>
Acesse também: Webly
May/082
Gerando Números aleatórios, Randomize
Gerar números randômicos é bem fácil.
Fica mais fácil criar uma função para receber os valores, assim tornando a função "livre" para ser usada em todo o projeto!
<% Function GerarRandomize(Valores) Dim Numeros : Numeros = "0123456789" Randomize For I = 1 To Valores Dim Num : Num = Mid(Numeros, Int(35 * Rnd) + 1, 1) Dim Chave : Chave = Chave + Num Next GerarRandomize = Chave End Function Response.Write(GerarRandomize(10)) 'o número 10 significa quandos números serão gerados %>
Significado das funções:
MID(): Serve para tirar uma string entre dois valores
Sintaxe: MID(String, CaracterInicio, TamanhoSeleção)
RND(): Devolve um numero aleatório.
Antes de se usar esta função, use Randomize, para ele se basear no relógio do sistema e desta maneira não repetir valores.
Qualquer dúvida é só postar:
Acesse também: Webly
May/081
Traduzindo Textos com ASP
Geralmente em sistemas de médio e grande porte temos que fazer a tradução dele para outras línguas, por exemplo de português para inglês
Creie uma função bem simples utilizando a função nativa do VBScript chamada "EVAL"
Esse script pega os textos que estão dentro da função chamada "Traduz" e troca pela variável de mesmo nome.
Nesse script temos o include do arquivo com os textos convertidos para a língua inglesa.
<!--#Include File="en.asp"-->
<%
Function Traduz(Texto)
Traduz = Eval(Texto)
End Function
%>
<p><%=Traduz("titulo")%>: <input type="text" name="texto"></p>
<p><%=Traduz("valores")%>: <input type="text" name="valores"></p>
<p><%=Traduz("mais")%>: <input type="text" name="texto"></p>
Aqui segue o arquivo de include en.asp.
<% titulo = "title" valores = "values" mais = "more" %>
Super simples de entende, qualquer dúvida é só deixar um comentário!
Acesse também: Webly


