Newsgroup: it.comp.lang.javascript
Titolo: Probelma con somma e sottrazione

Ho scritto questo piccolo script per calcolare una somma di + valori
di text form:
function Money(){
engine=teamform.engine2.value;
chassis=teamform.engine2.value;
tyres=teamform.tyres2.value;
money=teamform.money2.value;
teamform.total.value=eval(money-(engine+chassis+tyres));
}
la funzione Money() viene chiamata con onBlur.
Perchè non funzione????

Il Tue, 17 Jul 2001 11:40:21 GMT, Tiziano ha scritto.....

Vediamo il codice completo.
-- 
Ciao, Riccardo
------------------------------------------------------------------------
WebMaster: ----> 
http://www.jsdir.com
 <---- (aka 
http://www.jspoint.it
)
              All the JavaScript you need
------------------------------------------------------------------------
               Nessun traguardo è abbastanza lontano.
------------------------------------------------------------------------

Vediamo il codice completo.
<script language="javascript">
function checkEngine () {
if (teamform.Engine.value == "Level A") {teamform.engine2.value = 400
}
else if (teamform.Engine.value == "Level B") {teamform.engine2.value =
275 }
else if (teamform.Engine.value == "Level C") {teamform.engine2.value =
200 }
else if (teamform.Engine.value == "Level D") {teamform.engine2.value =
150 }
else if (teamform.Engine.value == "Level E") {teamform.engine2.value =
105 }
else if (teamform.Engine.value == "Level F") {teamform.engine2.value =
75 }
else if (teamform.Engine.value == "Level G") {teamform.engine2.value =
55 }
else if (teamform.Engine.value == "Level H") {teamform.engine2.value =
45 }
else {teamform.engine2.value = 0}
}
function checkChassis () {
if (teamform.Chassis.value == "Level A") {teamform.chassis2.value =
300 }
else if (teamform.Chassis.value == "Level B") {teamform.chassis2.value
= 245 }
else if (teamform.Chassis.value == "Level C") {teamform.chassis2.value
= 195 }
else if (teamform.Chassis.value == "Level D") {teamform.chassis2.value
= 155 }
else if (teamform.Chassis.value == "Level E") {teamform.chassis2.value
= 115 }
else if (teamform.Chassis.value == "Level F") {teamform.chassis2.value
= 85 }
else if (teamform.Chassis.value == "Level G") {teamform.chassis2.value
= 55 }
else if (teamform.Chassis.value == "Level H") {teamform.chassis2.value
= 35 }
else {teamform.chassis2.value = 0}
}
function checkTyres () {
if (teamform.Tyres.value == "Level A") {teamform.tyres2.value = 180 }
else if (teamform.Tyres.value == "Level B") {teamform.tyres2.value =
140 }
else if (teamform.Tyres.value == "Level C") {teamform.tyres2.value =
110 }
else if (teamform.Tyres.value == "Level D") {teamform.tyres2.value =
85 }
else if (teamform.Tyres.value == "Level E") {teamform.tyres2.value =
65 }
else {teamform.tyres2.value = 0}
}
function Money() {
engine=teamform.engine2.value;
chassis=teamform.engine2.value;
tyres=teamform.tyres2.value;
money=teamform.money2.value;
teamform.total.value=eval(money-(engine+chassis+tyres));
}
</script>

ciao a tutti
vorrei sapere il comando per aprire una nuova pagina, dopo un alert, perň
nella finestra corrente!
grazie in anticipo
Ranieri

scusate! ho fatto un pò di casino...riposto la domanda ne punto giusto
Ranieri



 nella finestra corrente!
alert('ora ti cambio pagina');
location.href="tua.htm";
-- 
mailto: y = i
----------------------------------------
Vivo nel terrore di non essere frainteso 
(Oscar Wilde)

 location.href="tua.htm";
grazie!
Ranieri

 [... cut ...]
Non bsta, mi serve anche il codice HTML per capire come scattano gli eventi.
Anche perché da quel che vedo ho idea che usi delle <SELECT> list per far 
funzionare tutto l'ambaradan, ed ho idea che possiamo sistemare meglio il 
codice.


codice.
Ecco tutto il codice:
<html>
<head>
	<title>GrandPrix2.net League - The Best Grand Prix 2 League
Ever Made!</title>
 
<link href="
http://grandprix2.gamerspulse.com/league/league.css
"
rel=stylesheet type=text/css>
<style type="text/css">
         .form {background: #A4D1FF; font-family:
verdana,arial,helvetica; font-size: 9px; border: 1px solid }
</style>
<script language="javascript">
function checkEngine () {
if (teamform.Engine.value == "Level A") {teamform.engine2.value = 400
}
else if (teamform.Engine.value == "Level B") {teamform.engine2.value =
275 }
else if (teamform.Engine.value == "Level C") {teamform.engine2.value =
200 }
else if (teamform.Engine.value == "Level D") {teamform.engine2.value =
150 }
else if (teamform.Engine.value == "Level E") {teamform.engine2.value =
105 }
else if (teamform.Engine.value == "Level F") {teamform.engine2.value =
75 }
else if (teamform.Engine.value == "Level G") {teamform.engine2.value =
55 }
else if (teamform.Engine.value == "Level H") {teamform.engine2.value =
45 }
else {teamform.engine2.value = 0}
}
</SCRIPT>	
	<script language="javascript">
function checkChassis () {
if (teamform.Chassis.value == "Level A") {teamform.chassis2.value =
300 }
else if (teamform.Chassis.value == "Level B") {teamform.chassis2.value
= 245 }
else if (teamform.Chassis.value == "Level C") {teamform.chassis2.value
= 195 }
else if (teamform.Chassis.value == "Level D") {teamform.chassis2.value
= 155 }
else if (teamform.Chassis.value == "Level E") {teamform.chassis2.value
= 115 }
else if (teamform.Chassis.value == "Level F") {teamform.chassis2.value
= 85 }
else if (teamform.Chassis.value == "Level G") {teamform.chassis2.value
= 55 }
else if (teamform.Chassis.value == "Level H") {teamform.chassis2.value
= 35 }
else {teamform.chassis2.value = 0}
}
</SCRIPT>	
	<script language="javascript">
function checkTyres () {
if (teamform.Tyres.value == "Level A") {teamform.tyres2.value = 180 }
else if (teamform.Tyres.value == "Level B") {teamform.tyres2.value =
140 }
else if (teamform.Tyres.value == "Level C") {teamform.tyres2.value =
110 }
else if (teamform.Tyres.value == "Level D") {teamform.tyres2.value =
85 }
else if (teamform.Tyres.value == "Level E") {teamform.tyres2.value =
65 }
else {teamform.tyres2.value = 0}
}
</SCRIPT>	
</head>
 
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="15" leftmargin="0"
rightmargin="0">
<div align="center">
	 <a href="
http://grandprix2.gamerspulse.com/league
"><img
src="
http://grandprix2.gamerspulse.com/league/img/leaguelogo2.jpg
"
width="500" border="0" alt="GrandPrix2.net League Logo"></a><br>
 
<table border="0" width="500" cellspacing="0" cellpadding="0">
	   <tbody>
	   <tr>
	   	   <td bgcolor="#000000" nowrap rowspan="3"
valign="top" width="2"><img border="0" height="1"
src="
http://grandprix2.gamerspulse.com/league/img/spacer.gif
"
width="1"></td>
 
		<td colspan="3" nowrap valign="top" width="496">
		<center><br>
			<!-- Begin AdRotator.com's AdButler Code  -->
			<IFRAME
SRC="
http://imgserv.adbutler.com/adserve/;ID=114982;size=468x60;setID=29602;aff=on;loc=0;type=iframe
"
WIDTH=468 HEIGHT=60 FRAMEBORDER=0 BORDER=0 MARGINWIDTH=0
MARGINHEIGHT=0 VSPACE=0 HSPACE=0 SCROLLING=NO>
			<SCRIPT
SRC="
http://imgserv.adbutler.com/adserve/;ID=114982;size=468x60;setID=29602;aff=on;loc=0;type=js
"
LANGUAGE="JAVASCRIPT">
			</SCRIPT>
			<NOSCRIPT>
			<a
href="
http://imgserv.adbutler.com/go2/;ID=114982;size=468x60;setID=29602;aff=on;loc=0
">
			<img
src="
http://imgserv.adbutler.com/adserve/;ID=114982;size=468x60;setID=29602;aff=on;loc=0;type=img
"
border="0" 	height="60" width="468"></a>
			</NOSCRIPT>
			</IFRAME>
			<!-- End AdRotator.com's AdButler Code  -->
			<img
src="
http://grandprix2.gamerspulse.com/league/img/newsline.gif
"
border="0" width="418" height="1"></center>
			<div align="center">
				 <table border="0" cellpadding="4"
cellspacing="0" width="418">
        		 		<tbody>
        				<tr>
          					<td width="418"><br>
            				<center>
            						<table
bgcolor="#FFFFFF" border="0" cellpadding="4" cellspacing="0"
width="418">
<tbody>
<tr>
<td width="418"><font class="title"><center><b>REGISTER A NEW
TEAM</b></font></td>
</tr>
</tbody>
</table>
							</center><br>
						<table border="0"
cellpadding="4" cellspacing="0" width="418">
        		 		<tbody>
        				<tr>
          					<td width="418">
							<img
src="
http://grandprix2.gamerspulse.com/league/img/newsline.gif
"
border="0" width="418" height="1">
 
							<center><font
class="main">Fill in the form to register a new team
 
 
							<FORM
ENCTYPE="multipart/form-data"
action="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi
"
method="POST" name="teamform">
		<input type=hidden name="db" value="teams">
		<input type=hidden name="uid"
value="admin.99632899657675">	
<table border="0" cellpadding="4" cellspacing="0">
        <tr>
		<td valign="middle" width="150"><font
class="join"><b>ID:</b></font></td>
        <td valign="middle" width="346">&nbsp;<INPUT TYPE="TEXT"
NAME="ID" VALUE="2" SIZE="3" MAXLENGTH="3" class="form"
onFocus="this.blur()"></TD></TR>
		<tr>
        <td valign="middle" width="150"><font
class="join"><b>Team:</b></font></td>
        <td valign="middle" width="346">&nbsp;<INPUT TYPE="TEXT"
NAME="Team" VALUE="" SIZE="40" MAXLENGTH="255" class="form"></TD></TR>
        <td valign="middle" width="150"><font class="join"><b>Engine
Name:</b></font></td>
        <td valign="middle" width="346">&nbsp;<INPUT TYPE="TEXT"
NAME="EngineName" VALUE="" SIZE="40" MAXLENGTH="255"
class="form"></TD></TR>
		<tr><td valign="middle" width="150"><font
class="join"><b>Website:</b></font></td>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="Website" VALUE="http://" SIZE="40" MAXLENGTH="255"
class="form"></TD></TR>
		<tr><td valign="middle" width="150"><font
class="join"><b>Manager:</b></font></td>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="Manager" VALUE="" SIZE="40" MAXLENGTH="255"
class="form"></TD></TR>
		<tr><td valign="middle" width="150"><font
class="join"><b>Manager email:</b></font></td>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="Email" VALUE="" SIZE="40" MAXLENGTH="255"
class="form"></TD></TR>
 
        <tr><td valign="middle" width="150"><font
class="join"><b>Date: </FONT></TD>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="Date" VALUE="28-Jul-2001" SIZE="12" MAXLENGTH="12"
onFocus="this.blur()" class="form"></TD></TR>
        <tr><td valign="middle" width="150"><font class="join"><b>1st
Driver: </FONT></TD>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="DriverA" VALUE="" SIZE="40" MAXLENGTH="255"
class="form"></TD></TR>
        <tr><td valign="middle" width="150"><font class="join"><b>1st
Driver ID: </FONT></TD>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="DriverAID" VALUE="" SIZE="10" MAXLENGTH="10"
class="form"></TD></TR>
        <tr><td valign="middle" width="150"><font class="join"><b>2nd
Driver: </FONT></TD>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="DriverB" VALUE="" SIZE="40" MAXLENGTH="255"
class="form"></TD></TR>
        <tr><td valign="middle" width="150"><font class="join"><b>2nd
Driver ID: </FONT></TD>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="DriverBID" VALUE="" SIZE="10" MAXLENGTH="10"
class="form"></TD></TR>
		<tr><td valign="middle" width="150"><font
class="join"><b>Engine:</FONT></TD>
                <td valign="middle" width="346">&nbsp;<SELECT
NAME="Engine" onChange="checkEngine();"
class="form"><OPTION>---<OPTION value='Level A'>Level A<OPTION
value='Level B'>Level B<OPTION value='Level C'>Level C<OPTION
value='Level D'>Level D<OPTION value='Level E'>Level E<OPTION
value='Level F'>Level F<OPTION value='Level G'>Level G<OPTION
value='Level H'>Level H<OPTION value='Level I'>Level I</SELECT> <INPUT
TYPE="TEXT" NAME="engine2" SIZE="3" MAXLENGTH="3"
onFocus="this.blur()" class="form"> <font class="join">Million
$</TD></TR>
		<tr><td valign="middle" width="150"><font
class="join"><b>Chassis:</FONT></TD>
                <td valign="middle" width="346">&nbsp;<SELECT
NAME="Chassis" onChange="checkChassis();"
class="form"><OPTION>---<OPTION value='Level A'>Level A<OPTION
value='Level B'>Level B<OPTION value='Level C'>Level C<OPTION
value='Level D'>Level D<OPTION value='Level E'>Level E<OPTION
value='Level F'>Level F<OPTION value='Level G'>Level G<OPTION
value='Level H'>Level H<OPTION value='Level I'>Level I</SELECT> <INPUT
TYPE="TEXT" NAME="chassis2" SIZE="3" MAXLENGTH="3"
onFocus="this.blur()" class="form"> <font class="join">Million
$</TD></TR>
		<tr><td valign="middle" width="150"><font
class="join"><b>Tyres:</FONT></TD>
                <td valign="middle" width="346">&nbsp;<SELECT
NAME="Tyres" onChange="checkTyres();" class="form"><OPTION>---<OPTION
value='Level A'>Level A<OPTION value='Level B'>Level B<OPTION
value='Level C'>Level C<OPTION value='Level D'>Level D<OPTION
value='Level E'>Level E<OPTION value='Level F'>Level F</SELECT> <INPUT
TYPE="TEXT" NAME="tyres2" SIZE="3" MAXLENGTH="3" onFocus="this.blur()"
class="form"> <font class="join">Million $</TD></TR>
        <tr><td valign="middle" width="150"><font
class="join"><b>Money: </FONT></TD>
                <td valign="middle" width="346">&nbsp;<INPUT
TYPE="TEXT" NAME="Money" VALUE="250" SIZE="3" MAXLENGTH="3"
class="form"></TD></TR>
 
 
        <tr><td valign="middle" width="150"><font
class="join"><b>Description:</FONT></TD>
                <td valign="middle" width="346">&nbsp;<TEXTAREA
NAME="Description" ROWS="4" COLS="40" WRAP="VIRTUAL" MAXLENGTH="255"
class="form"></TEXTAREA></TD></TR>
 
    <tr><td valign="middle" width="150"><font class="join"><b>Team
Pic:</TD>
         <td valign="middle" width="346">&nbsp;<INPUT TYPE="FILE"
NAME="Filename" SIZE="50" class="form"></TD></TR>
 
<tr>
<td align="center" colspan="2"><font size="2" face="verdana,
helvetica, arial"><input type="SUBMIT" name="add_record"
value="register" class="form"></font>
<font size="2" face="verdana, helvetica, arial"><INPUT TYPE="SUBMIT"
NAME="logoff" VALUE="clear" class="form"></font></td>
</tr>
</table>
</form>
<P align=center><font class="main">| <A
HREF="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi?db=teams&uid=admin.99632899657675
">Main
Menu</A> | <A
HREF="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi?db=teams&uid=admin.99632899657675&add_form=1
">Register</A>
| <A
HREF="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi?db=teams&uid=admin.99632899657675&modify_form=1&ID=*
">Modify</A>
| <A
HREF="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi?db=teams&uid=admin.99632899657675&view_records=1&ID=*
">List
All Teams</A> | <A
HREF="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi?db=teams&uid=admin.99632899657675&admin_display=1
">Admin</A>
| <A
HREF="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi?db=teams&uid=admin.99632899657675&modify_search=1
">Modify
all</A> | <A
HREF="
http://grandprix2.gamerspulse.com/cgi-bin/dbman/db.cgi?db=teams&uid=admin.99632899657675&logoff=1
">Log
Off</A> |</font></p>	
<center><font class="main">Database Powered by <A
HREF="
http://www.gossamer-threads.com
">Gossamer Threads
Inc.</A></font></center>
			</font></center>
							</td>
						</tr>
						</tbody>
						</table>
				<center><br><br>
            	<div align="center">
            	<font class="copy">&copy; 2001 GrandPrix2.net. All
rights reserved.<br>
				Best viewed in Microsoft Internet
Explorer 5.0 or higher in 1024x768 24 bit color
				</font>
				</div>
				</center>
				</td>
				</tr>
				</tbody>
				</table>
				</div>
			</td>
			<td bgcolor="#000000" nowrap rowspan="3"
valign="top" width="2"><img border="0" height="1"
src="
http://grandprix2.gamerspulse.com/league/img/spacer.gif
"
width="1"></td>
 
					</tr>
		</tbody>
 
	</table><img
src="
http://grandprix2.gamerspulse.com/league/img/endline.gif
"
border="0" height="2" width="500"></div>
 
</body>
</html>

Nel post precedente mi sono dimenticato di dire cosa vorrei che lo
script facesse:
lo script che ho in mente dovrebbe sommare i 3 valori dei select
(Engine, Chassis e Tyres) e poi dovrebbe sotrarre il totale della
somma ad un valore prestabilito e mostrare questo valore in un altro
<input type="text2" ....> (che nn ho ancora aggiunto nel form)

, 
mont...@iname.com
 
says...

Un po' di modifiche:
Innanzitutto usa un nome diverso per la funzine, se usi ancora "money" 
l'interprete JavaScrit trova un duplicato con il campo testo.
Poi nella tua funzione di somma (primo post) avevi messo due volte 
"engine2" (ma questo ancora non c'entrava nulla :-)
In ogni caso non avevi nessun campo "Money2" nel form, e poi conviene, 
per regola, usare comunque "document" come oggetto padre per i campi del 
form.
In conclusione:
- cambia il campo money con questa sintassi: <INPUT TYPE="TEXT" 
NAME="Money" VALUE="250" SIZE="3" MAXLENGTH="3" class="form">
Aggiungi il campo testo ed usa questa funzione:
function somma()
	{
	with (document.teamform)
		{
		engine=engine2.value;
		chassis=chassis2.value;
		tyres=tyres2.value;
		money=Money.value;
		total.value=eval(money-(engine+chassis+tyres));
		}
	}
Ho provato e mi sembra che vada.
