|
Answer» hi guys there is a problem with this FORM when i click the button it does not call the function up
the chrome debug window says : Reference error sub has not been defined
anyone know why?
Code: [Select]<html> <head> <script type="text/javascript"> function sub(form) { var item = form.ship.selectedIndex; var result = form.ship.options[item].value; var speed = 0; var tech_multiply = 0; var result_speed = 0; var type = "Inter"; if (result=="Corvette") { speed = 8; type = "Stellar"; } else if (result=="Recycler" || result=="DESTROYER" || result=="Frigate" || result=="IonFrigate") { speed = 5; type = "Stellar"; } else if (result=="ScoutShip") { speed = 12; type = "Warp"; } else if (result=="OutpostShip") { speed = 3; type = "Warp"; } else if (result=="Cruiser" || result=="carrier") { speed = 4; type = "Warp"; } else if (result=="HeavyCruiser" || result=="Battleship" || result=="FleetCarrier") { speed = 3; type = "Warp"; } else if (result=="Dreadnought") { speed = 2; type = "Warp"; } else { speed = 1; type = "Warp"; } if (type=="Stellar") { var techlevel = form.stellar.value; } else if (type=="Warp") { var techlevel = form.warp.value; } if !(techlevel==0) { tech_multiply = (techlevel*0.05)+1 result_speed = speed*techmultiply document.getElementById("Display").innerHTML=result_speed } else { document.getElementById("Display").innerHTML="Unable to plot COURSE - no tech levels or incorrect FORMAT" } } </script> </head> <body> <form action="" name="Ship_Speed_Form"> Select slowest unit: <select name="ship"> <option value="Corvette" selected="selected">Corvette</option> <option value="Recycler">Recycler</option> <option value="Destryer">Destryer</option> <option value="Frigate">Frigate</option> <option value="IonFrigate">Ion Frigate</option> <option value="ScoutShip">Scout Ship</option> <option value="OutpostShip">Outpost Ship</option> <option value="Cruiser">Cruiser</option> <option value="Carrier">Carrier</option> <option value="HeavyCruiser">Heavy Cruiser</option> <option value="Battleship">Battleship</option> <option value="FleetCarrier">Fleet Carrier</option> <option value="Dreadnought">Dreadnought</option> <option value="Titan">Titan</option> <option value="Leviathan">Leviathan</option> <option value="DeathStar">Death Star</option> </select></br> </br> Stellar Drive Level : <input type="text" size="13" maxlength="12" name="stellar" value=""/><br /> </br> Warp Drive Level : <input type="text" size="13" maxlength="12" name="warp" value=""/><br /> </br> <button type="button" onclick="sub(this.form)">Calculate</button> </form> <p id="Display">This is a paragraph.</p> </body> </html>sub() is undefined due to a syntax error in the function. Try changing:
Code: [Select]if !(techlevel==0) to
Code: [Select]if (techlevel!=0) Incidentally, if you do your HTML programming in a syntax-highlighting IDE like NetBeans or Eclipse, the IDE will spot a lot of errors like this for you.I agree with Rob as I've tested it and it works. And also if you change
THIS below
Code: [Select]<button type="button" onclick="sub(this.form)">Calculate</button>
TO this
Code: [Select]<button type="button" onclick="sub(form)">Calculate</button>
This lets your message
Quote "Unable to plot course - no tech levels or incorrect format"
Come up on the screen.
Hope this helps.
B2
|