problem with the jsp

Hello,

We are a team with projects for homebanking at Internet. Everything is working on Internet Explorer 5.5 and others versions, but at Netscape, our JSPs don t work because they have functions of Javascripts, the system get those JSPS , but does not make any functions work. The validations don t work :( I hope someone can give us a help.

Thanks,

Alex Vasconcelos (Portugal)

[412 byte] By [al3xii] at [2007-9-26 1:19:18]
# 1
show some codeThings that work in IE will not always work in NNlike some OnClick events it is better to put <a href="javascript:myFunction();"> around the buttons
JavaDen at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi and thanks for helping us! This is the code we are using in the JSP (the all code) :

We know this maybe too much code, but if you want, we can take part of this :) I hope you can help us again!

<html>

<%@ include file ="includecbtf.jsp" %>

<head>

<!--sc001_captura_datos_POR.jsp-->

<title> - Emprstimos - Simula o de Cr dito</title>

<LINK rel=STYLESHEET type='text/css' href="estilos/tablas.css">

<script language="Javascript" src="js/sc001_captura_datos.js"></script>

<script language="Javascript" src="js/utilidades.js"> </script>

<script language="Javascript" src="js/tiempo.js"> </script>

<script language="Javascript">

<%

java.util.Vector vLinha = (java.util.Vector)(datos.get("ListaCreditos"));

%>

var tamlin = <%=vLinha.size()%>;

var linhaCredito = new Array(tamlin);

<%

int i = 0;

int j = 0;

String fila ="";

try

{

java.util.Enumeration el = vLinha.elements();

java.util.Hashtable linhaCredito;

%>

<%

while (el.hasMoreElements()) {

linhaCredito = (java.util.Hashtable)el.nextElement();%>

linhaCredito[<%=i%>] = new Array(tamlin);

linhaCredito[<%=i%>][0] = "<%= (String)linhaCredito.get("CodigoCredito")%>";

linhaCredito[<%=i%>][1] = "<%= (String)linhaCredito.get("Descripcion")%>";

linhaCredito[<%=i%>][2] = "<%= (String)linhaCredito.get("tipoCredito")%>";

linhaCredito[<%=i%>][3] = "<%= (String)linhaCredito.get("CodProduto")%>";

linhaCredito[<%=i%>][4] = "<%= (String)linhaCredito.get("Valormax")%>";

linhaCredito[<%=i%>][5] = "<%= (String)linhaCredito.get("Prazomax")%>";

linhaCredito[<%=i%>][6] = "<%= (String)linhaCredito.get("Prazomin")%>";

<%

i++;

}//end del while.

}catch (Exception e){

// Seguimos.

}

%>

function preencherSelect ()

{

var selec = document.forms[0].moneda.options[document.forms[0].moneda.selectedIndex].value;

if(selec=="PTE")

{

var sel= "96";

}

else

{

var sel="97";

}

var cont = 0;

var j=1;

for(var h=0; h<tamlin; h++)

{

if (linhaCredito[h][3]==sel)

{

cont++;

}

}

document.forms[0].credito.options.length=0;

document.forms[0].credito.options.length = cont+1;

document.forms[0].credito.options[0].value = "";

document.forms[0].credito.options[0].text = "..........";

for(var i=0; i><tamlin; i++)

{

if (linhaCredito[3]==sel)

{

document.forms[0].credito.options[j].value = linhaCredito[4] + "," + linhaCredito[5] + "," + linhaCredito[6] + "," + linhaCredito[1] + "," + linhaCredito[0];

document.forms[0].credito.options[j].text = linhaCredito[1];

j++;

}

}

}

></script>

</head>

<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" class="pag-contenido" onLoad="controlSesion(); preencherSelect ();">

<center>

<table border="0" cellpadding="0" cellspacing="0" width="500">

<tr>

<td colspan="3"><img src="images/linea1.gif" border="0"></td>

</tr>

<tr>

<td width="250"><img src="images/prestamos.gif" border="0"></td>

<td width="82"><img src="images/titular.gif" border="0"></td>

<td width="169" class="fondotitular"><font class="texttitular"><%= datos.get("usuario")%></font></td>

</tr>

<tr>

<td colspan="3"><img src="images/linea1.gif" border="0"></td>

</tr>

</table>

</center>


<center>

<table cellpadding="3" cellspacing="1" border="0" align=center width="535">

<tr>

<%

out.println("<form method=\"post\" name=\"captura\" action=\"" + urls.get("action") + "\"> ");

%>

<td class="cabeceratitulo" colspan="4"><p class="titulotabla">Simula es Crdito ao Consumo / Habita o</p></td>

</tr>

<tr>

<td class="formgrisosc" width="30%"><p class="dato">Moeda dos Dados:</p></td>

<td class="formgrisosc" width="10%">

<SELECT name="moneda" class="formgriscla" onChange="javascript:preencherSelect();">

<option selected value="">..........</option>

<option value="PTE">Escudos</option>

<option value="EUR">Euros</option>

</SELECT>

</td>

<td class="formgrisosc" width="35%"><p class="dato">Linha de Crdito: </p></td>

<td class="formgrisosc" width="25%">

<select name="credito" size="1" class="formgrisosc">

<%

java.util.Vector v2 = (java.util.Vector)(datos.get("ListaCreditos"));

java.util.Enumeration e2 = v2.elements();

java.util.Hashtable elem2= null;

%>

<option selected value="">..........</option>

<%

while (e2.hasMoreElements()){

elem2 = (java.util.Hashtable)(e2.nextElement());

String Produto = ((String)elem2.get("CodProduto")).trim();

String Credito = ((String)elem2.get("Descripcion")).trim();

String Codigo = ((String)elem2.get("CodigoCredito")).trim();

String Valor = ((String)elem2.get("Valormax")).trim();

String PrzMax = ((String)elem2.get("Prazomax")).trim();

String PrzMin = ((String)elem2.get("Prazomin")).trim();

if (Produto.equals("97")) {

out.println("<option value=\"" + Valor +"," + PrzMax +"," + PrzMin +"," + Codigo + "\">" + Credito + "</option>");

}

}

%>

</select>

</td>

</tr>

<tr>

<td class="formgriscla" width="20%"><p class="dato">Import ncia:</p></td>

<td class="formgriscla" width="30%"><input name="importe"type="text" size="20" maxlength="20" class="formgriscla"></td>

<td class="formgriscla" width="15%"><p class="dato">Muturio(s):</p></td>

<td class="formgriscla" width="35%">

<SELECT name="seguro" class="formgrisosc">

<option value="0">sem seguro</option>

<option value="1">1 mutu rio</option>

<option value="2">2 muturios</option>

</SELECT>

</td>

</tr>

<tr>

<td class="formgrisosc" width="35%"><P CLASS="DATO">Prazo da Opera o:</p></td>

<td class="formgrisosc" colspan="3"> <input name="numero" type="text" size="2" maxlength="2" class="formgrisosc">

<select name="prazo" size="1" class="formgrisosc">

<option value="2" selected>Meses</option>

<option value="3">Anos</option>

</select>

</td>

</tr>

<tr>

<td class="cabecera" colspan="4"><img src="images/1x1.gif" width=1 height=3 border="0"></td>

</tr>

</table>

<table border="0" cellspacing="2" cellpadding="0">

<tr>

<td valign="top"><a href="javascript:limpar();"><img src="images/limpar.gif" border="0" alt="Apagar"></a></td>

<td valign="top"><a href="javascript:Validar();"><img src="images/continuar.gif" border="0" alt="Continuar"></a></td>

</tr>

</table>

</center>

</form>

</body>

</html>

And this is the JS--(That makes the validations in Javascript.)

sc001_captura_datos.js

function Validar()

{

(theres no code...is just an example...)

if (ok) f.submit();

}

Best regards to you,

Alex Vasconcelos (we are with a big problem ;)

al3xii at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
what is the javascript error?
sribk at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
> what is the javascript error?There is no error, page displays but dont make the validation. If i click in a button like "continue" he doesn t make the validation, see the code i have :) thanks
al3xii at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

function Validar()

{

(theres no code...is just an example...)

if (ok) f.submit();

}

see what is "ok" and "f" where have you defined?

use document.forms[0].submit()...or what ever your formname

document.formname.submit()

you have not started <form> tag

sribk at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

> function Validar()

> {

>

> (theres no code...is just an example...)

>

> if (ok) f.submit();

> }

>

>

>

> see what is "ok" and "f" where have you defined?

>

> use document.forms[0].submit()...or what ever your

> formname

>

> document.formname.submit()

>

> you have not started <form> tag

see the code, (JS)

function Validar()

{

var f=document.forms[0];

var ok = true;

var numeroER = /(\d)/;

//Faz a valida o do campo Linha de Credito, tem de estar uma das op es seleccionada

if((f.moneda.value=="")&& ok)

{

alert ("Deve seleccionar uma das op es do campo Moeda dos Dados.");

f.moneda.focus();

ok=false;

}

//Faz a valida o do campo Linha de Credito, tem de estar uma das op es seleccionada

if((f.credito.value=="")&& ok)

{

alert ("Deve seleccionar uma das op es do campo Linha de Cr dito.");

f.credito.focus();

ok=false;

}

if(ok){//inicio do ok1

var x = f.credito.value;

var tx = f.credito.value.length;

var nvirg = 0;

var nbytes = 0;

for (j = 0; j < tx; j++)//percorre a string linha de creditito at ao fim.

{

if (x.charAt(j) == ',') //percorre a string e verifica quais s o os campos que so ",".

{

nvirg++ ; //conta o numero de virgulas

nbytes = j ; //conta o numero de campos at atingir cada virgula

if (nvirg == 1)

{

valmax = x.substring(0,nbytes);

vmax = eval(valmax);

ybytes = nbytes;

}

if (nvirg == 2)

{

prazomax = x.substring(ybytes+1,nbytes);

ybytes = nbytes;

if (prazomax.charAt(0) == "3")

{

pmax = (eval(prazomax.substr(2,3))) * 12;

}

else

{

pmax = eval(prazomax.substr(2,3));

}

}

if (nvirg == 3)

{

prazomin = x.substring(ybytes+1,nbytes);

ybytes = nbytes;

if (prazomin.charAt(0) == "3")

{

pmin = (eval(prazomin.substr(1,3))) * 12;

}

else

{

ppmin = prazomin.substr(1,3);

pmin = eval(ppmin.substring(1,3));//evita o erro de arredondamento provocado pelo eval sobre um valor com um zero na primeira posi o

}

}

}

}

//f.credito.Change = codi;

//Verifica se o campo montante est vazio e semoeda

//var ent = f.montante.value;

var tamanho = f.importe.value.length;

var valor = f.importe.value;

if (((tamanho == 0) || (valor == 0)) && ok)

{

alert ("O Campo Importancia tem de ser maior que zero.");

f.importe.focus();

f.importe.select();

ok = false;

}

else

{

for (j = 0; j < tamanho; j++)

{

xx = valor.charAt(j);

if ((!(xx.match(numeroER)) && ok))

{

alert ("Deve preencher o campo Importncia com caracteres num ricos inteiros.");

f.importe.focus();

f.importe.select();

ok = false;

}

}

}

if (ok){ // inicio do ok2

if ((eval(valor) > vmax) && ok)

{

alert ("O Campo Importncia deve ser igual ou inferior a " + vmax +".");

f.importe.focus();

f.importe.select();

ok = false;

}

}//fim do ok2

// Valida o campo Tipo Prazo

var tipoprazo = f.prazo.value; //recebe o valor, semes ou ano

var numero = f.numero.value;

var num =f.numero.value.length;

if (((numero == 0) || (num == 0)) && ok)

{

alert ("O Tipo Prazo tem de ser maior que zero.");

f.numero.focus();

f.numero.select();

ok = false;

}

else

{

for (j = 0; j < num; j++)

{

xx = numero.charAt(j);

if ((!(xx.match(numeroER)) && ok))

{

alert ("O Campo Tipo Prazo deve ser numrico.");

f.numero.focus();

f.numero.select();

ok = false;

}

}

}

//inicio do ciclo ok3

if(ok){

if(tipoprazo == "3")

{

var num= (eval(numero)*12)

if ((eval(num) > pmax ) && ok)

{

alert ("O Campo Prazo da Opera o deve ser igual ou inferior a " + pmax/12 + " anos." );

f.numero.focus();

f.numero.select();

ok = false;

}

if ((eval(num) < pmin ) && ok)

{

alert ("O Campo Prazo da Opera o deve ser igual ou superior a " + pmin/12 + " anos." );

f.numero.focus();

f.numero.select();

ok = false;

}

}

else{

if ((eval(numero) > pmax ) && ok)

{

alert ("O Campo Prazo da Opera o deve ser igual ou inferior a " + pmax + " meses." );

f.numero.focus();

f.numero.select();

ok = false;

}

if ((eval(numero) < pmin ) && ok)

{

alert ("O Campo Prazo da Opera o deve ser igual ou superior a " + pmin + " meses." );

f.numero.focus();

f.numero.select();

ok = false;

}

}

}//fim do ciclo ok3

}//fim do ok1

if (ok) f.submit();

}

:)) Its ok, I think.

al3xii at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
you see instead of "substring" use "substr" for String variables.. Substring is a js function .. check this out
sribk at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
> you see instead of "substring" use "substr" for String> variables.. Substring is a js function .. check this> out Ive checked, the browser just "thinks" and nothing else... the same.. it s difficult! ;) what you suggest?
al3xii at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
just type javascript: on the location bar.. what is the errors it is displaying?
sribk at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
theres no error message ... in the I.Explorer it works. Netscape... no way... it s strange...
al3xii at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
I have similar jsp in my project, but it does work fine in IE and Netscape, I think you first should make sure anchor link does call javascript validation function, you may put alert box in begining of script. if it does, then check for validation in detail.
sunnyliu at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

> I have similar jsp in my project, but it does work

> fine in IE and Netscape, I think you first should make

> sure anchor link does call javascript validation

> function, you may put alert box in begining of script.

> if it does, then check for validation in detail.

the submit form does work.... if we cut everything, and we only put the variables and the submit... everything work...Its strange!!

al3xii at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13

> theres no error message ... in the I.Explorer it

> works. Netscape... no way... it s strange...

I ran into this problem recently as well. I finally figured out that it has something to do with a namespace-ish issue, where for some reason Nutscrape can't see the function that you are calling. You can try moving the <script src=...></script> tags closer to the actual calling line ( <form action=...> )

More importantly, though, I notice that you essentially have the following:

<table>

<tr>

<form action=...>

<!-- form inputs, content, etc -->

</td>

</tr>

</table>

</form>

This is an invalid HTML tree layout. If you run it through any self-respecting validator it will complain loudly. =)

the proper sequence is

<form>

<table>

<!-- form inputs, content, etc -->

</table>

</form>

It looks like you were almost there, but you just put your <% out.println( "<form..." ) %> in the wrong place.

--David

sage_sam at 2007-6-29 0:51:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...