Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: problem with this form :(  (Read 3085 times)

0 Members and 1 Guest are viewing this topic.

steven32collins

    Topic Starter


    Intermediate
    • Experience: Beginner
    • OS: Windows XP
    problem with this form :(
    « on: November 24, 2011, 03:15:53 PM »
    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>
    Everything should be made as simple as possible, but not simpler.
    --Albert Einstein--

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: problem with this form :(
    « Reply #1 on: December 01, 2011, 02:16:25 AM »
    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.
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos

    Base2



      Beginner
    • Thanked: 3
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: problem with this form :(
      « Reply #2 on: December 02, 2011, 04:40:13 PM »
      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 :)