terça-feira, 20 de julho de 2010

ORDENAÇÃO DE TABELA PELO TÍTULO

if( isset($_GET['ordenar']) ){
$SQL = "SELECT...FROM...ORDER BY ".$_GET['ordenar'] ." ";

}else if( !isset($_GET['ordenar']) ){
$SQL = "SELECT...FROM...ORDER BY ... ";
}

...

NOS TITULOS:
href='#' style='color:#5C5C5C' onclick="javascript:window.location.href='URL.php?ordenar=num_nt'; " > < u> Nº Nota Técnica < /u>

...

href='URL.php?p=1&ordenar=".$_GET['ordenar']."' ...

quinta-feira, 15 de julho de 2010

Somar valores em javascript

Essas funções javascript somam valores de dois textbox e coloca o valor formatado em um terceiro:

//Essa função formata uma string em moeda
function moeda_format(valor){


var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var SeparadorMilesimo = '.';
var SeparadorDecimal = ',';
len = valor.length;
for(i = 0; i < len; i++)
if ((valor.charAt(i) != '0') && (valor.charAt(i) != SeparadorDecimal)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(valor.charAt(i))!=-1) aux += valor.charAt(i);
aux += key;
len = aux.length;
if (len == 0) valor = '';
if (len == 1) valor = '0'+ SeparadorDecimal + '0' + aux;
if (len == 2) valor = '0'+ SeparadorDecimal + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += SeparadorMilesimo;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
valor = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
valor += aux2.charAt(i);
valor += SeparadorDecimal + aux.substr(len - 2, len);
}

return valor;
}

//Essa funcao realiza a soma e deve ser chamada no evento OnBlur dos textbox que terão os valores somados


function soma_valores(){

var vl_repasse = document.getElementById('repasse_empreendimento').value;
var vl_contrapartida = document.getElementById('contrapartida_empreendimento').value;
var vl_final = 0.0;
var vl_final_formatado = '';
if (vl_contrapartida == ''){
vl_contrapartida = 0.0;
}else{
vl_contrapartida = vl_contrapartida.replace(/\./g , '*');
vl_contrapartida = vl_contrapartida.replace(',', '.');
vl_contrapartida = vl_contrapartida.replace(/\*/g , '');
}

if (vl_repasse == ''){
vl_repasse = 0.0;
}else{
vl_repasse = vl_repasse.replace(/\./g , '*');

vl_repasse = vl_repasse.replace(',', '.');
vl_repasse = vl_repasse.replace(/\*/g , '');

}


vl_final = parseFloat(vl_repasse) + parseFloat(vl_contrapartida);
vl_final_formatado = vl_final.toString().replace('.', ',');
vl_final_formatado = vl_final_formatado.replace(',', '');
vl_final_formatado = moeda_format(vl_final_formatado);
document.getElementById('valor_total').value = vl_final_formatado;



}

quinta-feira, 1 de julho de 2010

Input type=FILE no Chrome

< style >
div.fileinputs {
position: relative;
margin-top: 0px;
margin-left: 0px;
}

div.fakefile {
position: absolute;
top: 0px;
left: 0px;
margin-top: 0px;
margin-left: 0px;
z-index: 1;
}

input.file {
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;

height: 30px;
width: 350px;
}


div.fakefile input {
margin-bottom: 5px;
margin-left: 0;
}

input.file.hidden {
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
}
< / style>


echo " < div class='fileinputs' >
< input class='file' style='width:465px' name='file-original' type='file' id='file-original' onchange=\"document.getElementById('file-falso').value = this.value;\" />
< div class='fakefile'>
< input name='file-falso' type='text' id='file-falso' style='width:350px'/> < img style='margin-bottom:-7px' src='search.gif' />
< / div >
< / div >
";
} else{
echo "< input type='FILE' name='anexo_nt[]' id='anexo_nt[]' size='50' accept='application/msword' >"; }?>