Foros del Web » Programando para Internet » Javascript » Frameworks JS »

problemas con el siguiente codigo

Estas en el tema de problemas con el siguiente codigo en el foro de Frameworks JS en Foros del Web. Loque pasa es que pongo 1,234.00 al poner el 5 ocupa el lugar del 4 y no en uno de los ceros , este proframa ...
  #1 (permalink)  
Antiguo 15/12/2010, 00:16
Avatar de johnmad  
Fecha de Ingreso: diciembre-2010
Mensajes: 6
Antigüedad: 13 años, 4 meses
Puntos: 0
problemas con el siguiente codigo

Loque pasa es que pongo 1,234.00 al poner el 5 ocupa el lugar del 4 y no en uno
de los ceros , este proframa es para formato de moneda , si alguin puede ayudarme se lo agradeceria, este es el codigo:


>
<META HTTP-EQUIV="expires" CONTENT="Sat, 01 Dec 2001 00:00:00 GMT">
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="cache-conTRol" CONTENT="no-cache">
<TITLE>Unibolsa</TITLE>
</HEAD>

<script language="javascript">
function fn_vldNum(ND){
ND=ND==null?0:ND,
vl=window.event.srcElement.value,
crsrPos=getCursorPos();
tc=String.fromCharCode(window.event.keyCode);
if ( ND!=0 && vl.indexOf(".")==1 && tc=="." ) return true;
if( isNaN ( parseInt(tc,10) ) ) {
window.event.keyCode=" ";
if ( tc=="." && crsrPos <= vl.indexOf(".") ) {
setCursorPos( vl.indexOf(".") + 1 );
}
}
if( vl.indexOf(".") != -1 && crsrPos > vl.indexOf(".") ) {
var elem = vl.split(".",2);
if( elem[1].length >= ND ) {
window.event.keyCode=" ";
return false;
}
}
return true;
}
function setComas() {
trgt=window.event.srcElement, vl = trgt.value,

Num=vl.replace(/,/g, ""),
dec=Num.indexOf("."),
end=dec>-1?""+Num.substring(dec,Num.length):".00",
Num=""+parseInt(Num),
temp1="",
temp2="",
count=0;
crsrPos=getCursorPos();

// alert(vl);

if(isNaN(Num)) Num="0";
if(end.length==2) end+="0";
if(end.length==1) end+="00";
if(end=="") end+=".00";
for(k=Num.length-1;k>=0;k--) {
oneChar=Num.charAt(k);
if(count==3) { temp1=temp1+","+oneChar,count=1; continue; }
else temp1=temp1+oneChar,count++;
}
for(k=temp1.length-1;k>=0;k--) oneChar=temp1.charAt(k), temp2+=oneChar;
// return temp2+end;

trgt.value=temp2+end;
setCursorPos( crsrPos );
return true;
}


function getCursorPos() {
var tb = window.event.srcElement;
cursor = -1;
if (document.selection && (document.selection != 'undefined')) {
var _range = document.selection.createRange();
contador=0;
while (_range.move('character', -1)) contador++;
cursor = contador;
}
else if (tb.selectionStart >= 0) cursor = tb.selectionStart;
return cursor;
}

function ssetCursorPos() {
var tb = window.event.srcElement;
if (document.selection && (document.selection != 'undefined')) {
var _range = document.selection.createRange();
// alert( _range.text )
_range.text = "Hola";
_range.move('character', -2);
}
else if (tb.selectionStart >= 0) cursor = tb.selectionStart;
return true;
}

function setCursorPos(crsrPs) {
oField = window.event.srcElement;
if (document.selection) {
oField.focus ();
var oSel = document.selection.createRange();
oSel.moveStart ('character', -oField.value.length);
oSel.moveStart ('character', crsrPs);
//oSel.moveEnd ('character', crsrPs);
oSel.moveEnd ('character', 0);
oSel.select();
oSel.moveStart ('character', crsrPs);
}
else if (oField.selectionStart || oField.selectionStart == '0') {
oField.selectionStart = crsrPs;
oField.selectionEnd = crsrPs;
oField.focus ();
}
}


function ffn_FrmtNm(field,trgt) {
trgt=trgt==null?field:trgt,
Num=field.value.replace(/,/g, ""),
dec=Num.indexOf("."),
end=dec>-1?""+Num.substring(dec,Num.length):".00",
Num=""+parseInt(Num),
temp1="",
temp2="",
count=0;
if(isNaN(Num)) Num="0";
if(end.length==2) end+="0";
if(end.length==1) end+="00";
if(end=="") end+=".00";
for(k=Num.length-1;k>=0;k--) {
oneChar=Num.charAt(k);
if(count==3) { temp1=temp1+","+oneChar,count=1; continue; }
else temp1=temp1+oneChar,count++;
}
for(k=temp1.length-1;k>=0;k--) oneChar=temp1.charAt(k), temp2+=oneChar;

trgt.value=temp2+end;
return true;
}

function fn_FrmtNmCap(field,trgt) {
trgt.value=parseInt(field.value.replace(/,/gi, ""));
return true;
}

</script>
<input type="text" id="mi_texto" name="inVld" value="" OnKeyPress="if ( fn_vldNum() ) ;" onkeyup=" setComas(); ">

<SCRIPT>
function obten_elemento(){
var mi_campo = document.getElementById("mi_texto");
if(mi_campo.value != ""){
alert("has escrito: " +mi_campo.value);

var miCadena = mi_campo.value;
var elem = miCadena.split(".",2);
entero = elem[0];
decimal = elem[1];

}
else alert("introduce el numero");

}

function fnFind(){
var sWhere = oSel.options[oSel.selectedIndex].text;
alert(oPara.getAdjacentText(sWhere));
}
</SCRIPT>

desde ya gracias..........
  #2 (permalink)  
Antiguo 15/12/2010, 00:28
Avatar de johnmad  
Fecha de Ingreso: diciembre-2010
Mensajes: 6
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: problemas con el siguiente codigo

>
<META HTTP-EQUIV="expires" CONTENT="Sat, 01 Dec 2001 00:00:00 GMT">
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="cache-conTRol" CONTENT="no-cache">
<TITLE>Unibolsa</TITLE>
</HEAD>

<script language="javascript">
function fn_vldNum(ND){
ND=ND==null?0:ND,
vl=window.event.srcElement.value,
crsrPos=getCursorPos();
tc=String.fromCharCode(window.event.keyCode);
if ( ND!=0 && vl.indexOf(".")==1 && tc=="." ) return true;
if( isNaN ( parseInt(tc,10) ) ) {
window.event.keyCode=" ";
if ( tc=="." && crsrPos <= vl.indexOf(".") ) {
setCursorPos( vl.indexOf(".") + 1 );
}
}
if( vl.indexOf(".") != -1 && crsrPos > vl.indexOf(".") ) {
var elem = vl.split(".",2);
if( elem[1].length >= ND ) {
window.event.keyCode=" ";
return false;
}
}
return true;
}
function setComas() {
trgt=window.event.srcElement, vl = trgt.value,

Num=vl.replace(/,/g, ""),
dec=Num.indexOf("."),
end=dec>-1?""+Num.substring(dec,Num.length):".00",
Num=""+parseInt(Num),
temp1="",
temp2="",
count=0;
crsrPos=getCursorPos();

// alert(vl);

if(isNaN(Num)) Num="0";
if(end.length==2) end+="0";
if(end.length==1) end+="00";
if(end=="") end+=".00";
for(k=Num.length-1;k>=0;k--) {
oneChar=Num.charAt(k);
if(count==3) { temp1=temp1+","+oneChar,count=1; continue; }
else temp1=temp1+oneChar,count++;
}
for(k=temp1.length-1;k>=0;k--) oneChar=temp1.charAt(k), temp2+=oneChar;
// return temp2+end;

trgt.value=temp2+end;
setCursorPos( crsrPos );
return true;
}


function getCursorPos() {
var tb = window.event.srcElement;
cursor = -1;
if (document.selection && (document.selection != 'undefined')) {
var _range = document.selection.createRange();
contador=0;
while (_range.move('character', -1)) contador++;
cursor = contador;
}
else if (tb.selectionStart >= 0) cursor = tb.selectionStart;
return cursor;
}

function ssetCursorPos() {
var tb = window.event.srcElement;
if (document.selection && (document.selection != 'undefined')) {
var _range = document.selection.createRange();
// alert( _range.text )
_range.text = "Hola";
_range.move('character', -2);
}
else if (tb.selectionStart >= 0) cursor = tb.selectionStart;
return true;
}

function setCursorPos(crsrPs) {
oField = window.event.srcElement;
if (document.selection) {
oField.focus ();
var oSel = document.selection.createRange();
oSel.moveStart ('character', -oField.value.length);
oSel.moveStart ('character', crsrPs);
//oSel.moveEnd ('character', crsrPs);
oSel.moveEnd ('character', 0);
oSel.select();
oSel.moveStart ('character', crsrPs);
}
else if (oField.selectionStart || oField.selectionStart == '0') {
oField.selectionStart = crsrPs;
oField.selectionEnd = crsrPs;
oField.focus ();
}
}


function ffn_FrmtNm(field,trgt) {
trgt=trgt==null?field:trgt,
Num=field.value.replace(/,/g, ""),
dec=Num.indexOf("."),
end=dec>-1?""+Num.substring(dec,Num.length):".00",
Num=""+parseInt(Num),
temp1="",
temp2="",
count=0;
if(isNaN(Num)) Num="0";
if(end.length==2) end+="0";
if(end.length==1) end+="00";
if(end=="") end+=".00";
for(k=Num.length-1;k>=0;k--) {
oneChar=Num.charAt(k);
if(count==3) { temp1=temp1+","+oneChar,count=1; continue; }
else temp1=temp1+oneChar,count++;
}
for(k=temp1.length-1;k>=0;k--) oneChar=temp1.charAt(k), temp2+=oneChar;

trgt.value=temp2+end;
return true;
}

function fn_FrmtNmCap(field,trgt) {
trgt.value=parseInt(field.value.replace(/,/gi, ""));
return true;
}

</script>
<input type="text" id="mi_texto" name="inVld" value="" OnKeyPress="if ( fn_vldNum() ) ;" onkeyup=" setComas(); ">

<SCRIPT>
function obten_elemento(){
var mi_campo = document.getElementById("mi_texto");
if(mi_campo.value != ""){
alert("has escrito: " +mi_campo.value);

var miCadena = mi_campo.value;
var elem = miCadena.split(".",2);
entero = elem[0];
decimal = elem[1];

}
else alert("introduce el numero");

}

function fnFind(){
var sWhere = oSel.options[oSel.selectedIndex].text;
alert(oPara.getAdjacentText(sWhere));
}
</SCRIPT>
  #3 (permalink)  
Antiguo 15/12/2010, 00:30
Avatar de johnmad  
Fecha de Ingreso: diciembre-2010
Mensajes: 6
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: problemas con el siguiente codigo

alguien me puede ayudar
>
<META HTTP-EQUIV="expires" CONTENT="Sat, 01 Dec 2001 00:00:00 GMT">
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="cache-conTRol" CONTENT="no-cache">
<TITLE>Unibolsa</TITLE>
</HEAD>

<script language="javascript">
function fn_vldNum(ND){
ND=ND==null?0:ND,
vl=window.event.srcElement.value,
crsrPos=getCursorPos();
tc=String.fromCharCode(window.event.keyCode);
if ( ND!=0 && vl.indexOf(".")==1 && tc=="." ) return true;
if( isNaN ( parseInt(tc,10) ) ) {
window.event.keyCode=" ";
if ( tc=="." && crsrPos <= vl.indexOf(".") ) {
setCursorPos( vl.indexOf(".") + 1 );
}
}
if( vl.indexOf(".") != -1 && crsrPos > vl.indexOf(".") ) {
var elem = vl.split(".",2);
if( elem[1].length >= ND ) {
window.event.keyCode=" ";
return false;
}
}
return true;
}
function setComas() {
trgt=window.event.srcElement, vl = trgt.value,

Num=vl.replace(/,/g, ""),
dec=Num.indexOf("."),
end=dec>-1?""+Num.substring(dec,Num.length):".00",
Num=""+parseInt(Num),
temp1="",
temp2="",
count=0;
crsrPos=getCursorPos();

// alert(vl);

if(isNaN(Num)) Num="0";
if(end.length==2) end+="0";
if(end.length==1) end+="00";
if(end=="") end+=".00";
for(k=Num.length-1;k>=0;k--) {
oneChar=Num.charAt(k);
if(count==3) { temp1=temp1+","+oneChar,count=1; continue; }
else temp1=temp1+oneChar,count++;
}
for(k=temp1.length-1;k>=0;k--) oneChar=temp1.charAt(k), temp2+=oneChar;
// return temp2+end;

trgt.value=temp2+end;
setCursorPos( crsrPos );
return true;
}


function getCursorPos() {
var tb = window.event.srcElement;
cursor = -1;
if (document.selection && (document.selection != 'undefined')) {
var _range = document.selection.createRange();
contador=0;
while (_range.move('character', -1)) contador++;
cursor = contador;
}
else if (tb.selectionStart >= 0) cursor = tb.selectionStart;
return cursor;
}

function ssetCursorPos() {
var tb = window.event.srcElement;
if (document.selection && (document.selection != 'undefined')) {
var _range = document.selection.createRange();
// alert( _range.text )
_range.text = "Hola";
_range.move('character', -2);
}
else if (tb.selectionStart >= 0) cursor = tb.selectionStart;
return true;
}

function setCursorPos(crsrPs) {
oField = window.event.srcElement;
if (document.selection) {
oField.focus ();
var oSel = document.selection.createRange();
oSel.moveStart ('character', -oField.value.length);
oSel.moveStart ('character', crsrPs);
//oSel.moveEnd ('character', crsrPs);
oSel.moveEnd ('character', 0);
oSel.select();
oSel.moveStart ('character', crsrPs);
}
else if (oField.selectionStart || oField.selectionStart == '0') {
oField.selectionStart = crsrPs;
oField.selectionEnd = crsrPs;
oField.focus ();
}
}


function ffn_FrmtNm(field,trgt) {
trgt=trgt==null?field:trgt,
Num=field.value.replace(/,/g, ""),
dec=Num.indexOf("."),
end=dec>-1?""+Num.substring(dec,Num.length):".00",
Num=""+parseInt(Num),
temp1="",
temp2="",
count=0;
if(isNaN(Num)) Num="0";
if(end.length==2) end+="0";
if(end.length==1) end+="00";
if(end=="") end+=".00";
for(k=Num.length-1;k>=0;k--) {
oneChar=Num.charAt(k);
if(count==3) { temp1=temp1+","+oneChar,count=1; continue; }
else temp1=temp1+oneChar,count++;
}
for(k=temp1.length-1;k>=0;k--) oneChar=temp1.charAt(k), temp2+=oneChar;

trgt.value=temp2+end;
return true;
}

function fn_FrmtNmCap(field,trgt) {
trgt.value=parseInt(field.value.replace(/,/gi, ""));
return true;
}

</script>
<input type="text" id="mi_texto" name="inVld" value="" OnKeyPress="if ( fn_vldNum() ) ;" onkeyup=" setComas(); ">

<SCRIPT>
function obten_elemento(){
var mi_campo = document.getElementById("mi_texto");
if(mi_campo.value != ""){
alert("has escrito: " +mi_campo.value);

var miCadena = mi_campo.value;
var elem = miCadena.split(".",2);
entero = elem[0];
decimal = elem[1];

}
else alert("introduce el numero");

}

function fnFind(){
var sWhere = oSel.options[oSel.selectedIndex].text;
alert(oPara.getAdjacentText(sWhere));
}
</SCRIPT>

Etiquetas: siguiente
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:01.