Soy novato en esto de java, ya os dareis cuenta, supongo, y tengo un problema:
Desde las faqs saqué un formulario que luego imprime los datos en pantalla. Lo intenté modificar para mi uso pero me salió todo bien hasta que quiese hacer una operación en la que se visualizaría una cantidad "Total Importe" diferente según el cliente Hubiese elegido la opción "comprar "o "vender".
Este es el script. No se qué estoy haciendo mal:
Si el cliente elige comprar p.ej cantidad 1, el precio total sería 20, si elige vender, el precio total sería 16, pero me imprime 20
<html>
<head><script>
var precio=20
</script>
<script language="JavaScript">
function enviar(){
//document.frm2.submit();
alert("Documento enviado");
history.back();
}
function regresar(){
//document.frm2.submit();
history.back();
}
function confirma(){
var sNmb;
sNmb = document.frm.nmb.value;
sApe = document.frm.ape.value;
var sAM
if (nmb="comprar"){sAM=precio*sApe}else{sAM=precio*sA pe*0.80} <!--esta es la condición pero no se que hago mal--> with (document){
open();
write("<html><head>");
write(" </head><body><form name='frm2'>");
write(" <table border='0'>");
write(" <tr>");
write(" <td>");
write(" Ha elegido Usted");
write(" </td>");
write(" <td width='50' align='right'>");
write(sNmb);
write(" </td>");
write(" </tr>");
write(" <tr>");
write(" <td>");
write(" Acciones:");
write(" </td>");
write(" <td align='right'>");
write(sApe);
write(" </td>");
write(" </tr>");
write(" <tr>");
write(" <td>");
write(" Total importe:");
write(" </td>");
write(" <td align='right'>");
write(sAM);
write(" </td>");
write(" </tr>");
write(" <tr>");
write(" <td colspan='2' align='center'>");
write(" <input type='submit' onclick='javascript:alert(" + '"' + "Documento enviado" + '"' + ");history.back()' value='Enviar estos valores'>");
write(" <input type='button' onclick='javascript:history.back()' value='Volver sin enviar'>");
write(" </td>");
write(" </tr>");
write(" </table>");
write("</form></body></html>");
close();
}
}
</script>
</head>
<body> <script language="JavaScript">
document.write("precio de compra: " + precio +"<br>")
document.write("precio de venta: " + precio*0.80)
</script>
<form name="frm">
<table border="1" width="640" height="174">
<tr>
<td width="61" height="23">
Quiero:
</td>
<td width="888" height="23">
<select name="nmb">
<option value="comprar">comprar</option>
<option value="vender">vender</option>
</select>
</td>
</tr>
<tr>
<td width="61" height="23">
Cantidad:
</td>
<td width="888" height="23"><!--webbot bot="Validation"
B-Value-Required="TRUE" --><select name="ape">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</td>
</tr>
<tr>
<td width="61" height="23">
email:
</td>
<td width="888" height="23">
<input type="text" name="prf">
</td>
</tr>
<tr>
<td align="left" width="61" height="25">
Nombre:
</td>
<td align="left" width="642" valign="top" height="25">
<input type="text" name="T1" size="20">
</td>
</tr>
<tr>
<td align="left" width="61" height="19">
Contraseña:
</td>
<td align="left" width="642" valign="top" height="19">
<input type="text" name="T2" size="20">
</td>
</tr>
<tr>
<td align="left" width="207" height="25" valign="top">
<b>Solo para nuevos socios :</b> Repita contraseña:
</td>
<td align="left" width="423" height="25" valign="top">
<input type="text" name="T3" size="20">
</td>
</tr>
<tr>
<td colspan="2" align="center" width="630" height="25">
<input type="button" onclick="confirma()" value="Enviar">
</td>
</tr>
<tr>
<td colspan="2" align="center" width="630" height="25">
</td>
</tr>
</table>
</form>
</body>
</html>
Gracias de antemano. Os daré más el coñazo con esto seguro, porque querré hacer más modificaciones y tropezaré seguro.
He visto manuales, pero al fina siempre recurro al foro porque aquí se resuelven problemas.
Gracias.