29. januar 2007 - 19:43
Der er
16 kommentarer
Hjælp med script
Hej. Jeg har lavet et udregningsscript, som skal regne en værdi ud, men den skriver bare NaN, når jeg trykker udregn. Hvad har jeg gjort forkert? <html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Calculate your Global Value</title> </head> <body> <p style="margin-top: 0; margin-bottom: 0"><b><font face="Tahoma" size="6">Stage of Today</font></b></p> <p><!--webbot bot="HTMLMarkup" startspan --><script language="JavaScript"> function Calculate(thisform) { Resistance = thisform.Resistance.value; Sprint = thisform.Sprint.value; Climbing = thisform.Climbing.value; Plain = thisform.Plain.value; Cobblestones = thisform.Cobblestones.value; Technique = thisform.Technique.value; Downhill = thisform.Downhill.value; Hills = thisform.Hills.value; Aggressiviness = thisform.Aggressiviness.value; TeamWork = thisform.TeamWork.value; ResToday = thisform.ResToday; SprToday = thisform.SprToday; CliToday = thisform.CliToday; PlaToday = thisform.PlaToday; CobToday = thisform.CobToday; TecToday = thisform.TecToday; DowToday = thisform.DowToday; HilToday = thisform.HilToday; AggToday = thisform.AggToday; TeaToday = thisform.TeaToday; resultat = (Resistance * ResToday / 100 + Sprint * SprToday / 100 + Climbing * CliToday / 100 + Plain * PlaToday / 100 + Cobblestones * CobToday / 100 + Technique * TecToday / 100 + Downhill * DowToday / 100 + Hills * HilToday / 100 + Aggressiviness * AggToday / 100 + TeamWork * TeaToday / 100) thisform.GV.value=resultat return false; } </script><!--webbot bot="HTMLMarkup" endspan --><!--webbot bot="HTMLMarkup" startspan --> <form name="test" <form name="test1" ;"><BR> <input type="text" name="ResToday" size="10" value="Resistance"> <input type="text" name="SprToday" size="8" value="Sprint"> <input type="text" name="CliToday" size="8" value="Climbing"> <input type="text" name="PlaToday" size="8" value="Plain"> <input type="text" name="CobToday" size="12" value="Cobblestones"> <input type="text" name="TecToday" size="8" value="Technique"> <input type="text" name="DowToday" size="8" value="Downhill"> <input type="text" name="HilToday" size="8" value="Hills"> <input type="text" name="AggToday" size="14" value="Aggressiviness"> <input type="text" name="TeaToday" size="10" value="TeamWork"> </form><!--webbot bot="HTMLMarkup" endspan --></p> <br><br><br> <u> <b><font face="Tahoma" size="4">YOUR RIDER SKILLS</font></b></u><form name="test" onSubmit="return Calculate(this);"> <input type="text" name="Resistance" size="10" value="Resistance"> <input type="text" name="Sprint" size="8" value="Sprint"> <input type="text" name="Climbing" size="8" value="Climbing"> <input type="text" name="Plain" size="8" value="Plain"> <input type="text" name="Cobblestones" size="12" value="Cobblestones"> <input type="text" name="Technique" size="8" value="Technique"> <input type="text" name="Downhill" size="8" value="Downhill"> <input type="text" name="Hills" size="8" value="Hills"> <input type="text" name="Aggressiviness" size="14" value="Aggressiviness"> <input type="text" name="TeamWork" size="10" value="TeamWork"> <input type="text" name="GV" size="22" value="GV Total, don't write here!"> <input type="submit" value="Calculate GV"> </form><!--webbot bot="HTMLMarkup" endspan --></p> </body> </html>
Annonceindlæg fra FPT Software
29. januar 2007 - 19:45
#1
skal du ikke have nogle flere paranteser ind i den udregning?
29. januar 2007 - 19:47
#2
Du har også 3 forms??? hvoraf 2 af dem hedder der samme?
29. januar 2007 - 19:48
#3
og jeg ville nok heller ikke bruge "test" som et formnavn, da det nok er et reserved navn. Du mangler også at definere dine variabler som var?
29. januar 2007 - 19:48
#4
måske, du mener udenom hvor jeg dividerer med 100, ikke?
29. januar 2007 - 19:52
#5
Hvordan vil du have scriptet til at se ud?
29. januar 2007 - 19:54
#6
Kan godt nok ikke overskue det der lige nu. sidder midt i en pokertunering. Men, tror du har copy/pastet lidt for meget :)
29. januar 2007 - 19:55
#7
Okay, det er helt fint. Vinder du? :)
29. januar 2007 - 20:38
#8
<html> <head> <script language="javascript"> function CalculateThis() { var nr1 = document.getElementById('input1').value; var nr2 = document.getElementById('input2').value; var resultat = eval(nr1) + eval(nr2); alert(resultat); } </script> </head> <body> <input type="text" id="input1"><br> <input type="text" id="input2"><br> <input type="button" value="Regn" onClick="CalculateThis()"> </body> </html> simpel lommeregner. ved ikke om du kan lave noget ud fra det :)
30. januar 2007 - 15:18
#9
<ole> Undgå såvidt muligt funktionen eval, der er JS' ubestridt dårligst performende. Prøv i stedet: function calculateThis() { var nr1 = document.getElementById('input1').value*1; var nr2 = document.getElementById('input2').value*1; var resultat = nr1 + nr2; alert(resultat); } - og husk, et validt JS-tag ser sådan ud: <script type="text/JavaScript"> </script> Language-attributten har været derprecated i snart 10 år ;o) /mvh </bole>
30. januar 2007 - 16:16
#10
Man lærer noget nyt hver dag :)
30. januar 2007 - 17:58
#11
mange tak, jeg har fået det hele til virke. I er geniale!
30. januar 2007 - 18:06
#12
troede jeg, men den siger stadig NaN: <td width="100%"> <p style="margin-top: 0; margin-bottom: 0"><b> <font face="Tahoma" size="4" color="#FFFFFF"> STAGE OF TODAY</font></b></p> <p style="margin-top: 0; margin-bottom: 0"><font color="#FFFFFF"><!--webbot bot="HTMLMarkup" startspan --><html> <head> <script language="javascript"> function CalculateThis() { var nr1 = document.getElementById('resistance').value*1; var nr2 = document.getElementById('sprint').value*1; var nr3 = document.getElementById('climbing').value*1; var nr4 = document.getElementById('plain').value*1; var nr5 = document.getElementById('cobblestones').value*1; var nr6 = document.getElementById('technique').value*1; var nr7 = document.getElementById('downhill').value*1; var nr8 = document.getElementById('hills').value*1; var nr9 = document.getElementById('aggressiviness').value*1; var nr10 = document.getElementById('teamwork').value*1; var nr11 = document.getElementById('restoday').value*1; var nr12 = document.getElementById('sprtoday').value*1; var nr13 = document.getElementById('clitoday').value*1; var nr14 = document.getElementById('platoday').value*1; var nr15 = document.getElementById('cobtoday').value*1; var nr16 = document.getElementById('tectoday').value*1; var nr17 = document.getElementById('dowtoday').value*1; var nr18 = document.getElementById('hiltoday').value*1; var nr19 = document.getElementById('aggtoday').value*1; var nr20 = document.getElementById('teatoday').value*1; var resultat = nr1 * (nr11/100) + nr2 * (nr12/100) + nr3 * (nr13/100) + nr4 * (nr14/100) + nr5 * (nr15/100) + nr6 * (nr16/100) + nr7 * (nr17/100) + nr8 * (nr18/100) + nr9 * (nr19/100) + nr10 * (nr20/100); alert(resultat); } </script> </head> <body> <input type="text" id="restoday" value="Resistance">> <input type="text" id="sprtoday" value="Sprint">> <input type="text" id="clitoday" value="Climbing">> <input type="text" id="platoday" value="Plain">> <input type="text" id="cobtoday" value="Cobblestones">> <input type="text" id="tectoday" value="Technique">> <input type="text" id="dowtoday" value="Downhill">> <input type="text" id="hiltoday" value="Hills">> <input type="text" id="aggtoday" value="Aggressiviness">> <input type="text" id="teatoday" value="TeamWork">> <br><br><br><br> <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="4"><b> YOUR RIDER SKILLS</b></font></p> <input type="text" id="resistance" value="Resistance">> <input type="text" id="sprint" value="Sprint">> <input type="text" id="climbing" value="Climbing">> <input type="text" id="plain" value="Plain">> <input type="text" id="cobblestones" value="Cobblestones">> <input type="text" id="technique" value="Technique">> <input type="text" id="downhill" value="Downhill">> <input type="text" id="hills" value="Hills">> <input type="text" id="aggressiviness" value="Aggressiviness">> <input type="text" id="teamwork" value="TeamWork">> <input type="button" value="Calculate GV" onClick="CalculateThis()"> </body> </html><!--webbot bot="HTMLMarkup" endspan --></font></p> <p style="margin-top: 0; margin-bottom: 0"> </td> Har jeg nu kommet til at lave noget forkert igen? :(
30. januar 2007 - 18:36
#13
--><html> <head> <script language="javascript"> function CalculateThis() { var nr1 = document.getElementById('resistance').value*1; var nr2 = document.getElementById('sprint').value*1; var nr3 = document.getElementById('climbing').value*1; var nr4 = document.getElementById('plain').value*1; var nr5 = document.getElementById('cobblestones').value*1; var nr6 = document.getElementById('technique').value*1; var nr7 = document.getElementById('downhill').value*1; var nr8 = document.getElementById('hills').value*1; var nr9 = document.getElementById('aggressiviness').value*1; var nr10 = document.getElementById('teamwork').value*1; var nr11 = document.getElementById('restoday').value*1; var nr12 = document.getElementById('sprtoday').value*1; var nr13 = document.getElementById('clitoday').value*1; var nr14 = document.getElementById('platoday').value*1; var nr15 = document.getElementById('cobtoday').value*1; var nr16 = document.getElementById('tectoday').value*1; var nr17 = document.getElementById('dowtoday').value*1; var nr18 = document.getElementById('hiltoday').value*1; var nr19 = document.getElementById('aggtoday').value*1; var nr20 = document.getElementById('teatoday').value*1; var resultat = nr1 * (nr11/100) + nr2 * (nr12/100) + nr3 * (nr13/100) + nr4 * (nr14/100) + nr5 * (nr15/100) + nr6 * (nr16/100) + nr7 * (nr17/100) + nr8 * (nr18/100) + nr9 * (nr19/100) + nr10 * (nr20/100); alert(resultat); } </script> </head> <body> <input type="text" id="restoday" value="Resistance">> <input type="text" id="sprtoday" value="Sprint">> <input type="text" id="clitoday" value="Climbing">> <input type="text" id="platoday" value="Plain">> <input type="text" id="cobtoday" value="Cobblestones">> <input type="text" id="tectoday" value="Technique">> <input type="text" id="dowtoday" value="Downhill">> <input type="text" id="hiltoday" value="Hills">> <input type="text" id="aggtoday" value="Aggressiviness">> <input type="text" id="teatoday" value="TeamWork">> <br><br><br><br> <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="4"><b> YOUR RIDER SKILLS</b></font></p> <input type="text" id="resistance" value="Resistance">> <input type="text" id="sprint" value="Sprint">> <input type="text" id="climbing" value="Climbing">> <input type="text" id="plain" value="Plain">> <input type="text" id="cobblestones" value="Cobblestones">> <input type="text" id="technique" value="Technique">> <input type="text" id="downhill" value="Downhill">> <input type="text" id="hills" value="Hills">> <input type="text" id="aggressiviness" value="Aggressiviness">> <input type="text" id="teamwork" value="TeamWork">> <input type="button" value="Calculate GV" onClick="CalculateThis()"> </body> </html> virker fint her.. Du havde et par fejl. <html></html></body> var helt forkert placeret. scriptet kommer ihvertfald med et tal når jeg sætter nogle random tal ind i boksene nu
30. januar 2007 - 18:37
#14
errr... slet lige --> inden <html>
30. januar 2007 - 18:39
#15
hvis du skal have dette ind på en anden side, så skal du kopiere alt det mellem <head> og </head> og smide en imellem <head> og </head> på den anden side. samt det mellem <body> og </body> ind på den anden side mellem samme tags hvis der pludselig kommer flere <html><head><body> osv tags i samme fil så går det galt
30. januar 2007 - 19:08
#16
tak, det virkede lige pludseligt igen, selvom jeg ikke gjorde noget. hmm. men tak.
Vi tilbyder markedets bedste kurser inden for webudvikling