CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Conversion script not showing results (http://www.codingforums.com/showthread.php?t=194366)

Goldex 04-21-2010 10:29 AM

Conversion script not showing results
 
Hi,
Im need to create a conversion-script for a company that do step-competitions. You should be able to input a time-variable, choose what activity you did from a drop-down meny, click convert ("omvandla" in swedish") and the script prints what that is equal to in steps.
I found a code online that does other conversion so i just redid that code to fit my demands.
Everything looks alright in the browser, but the script doesnt print anything when i click "omvandla". Forgive me for posting the entire code, which is pretty long. But most of the code is just repetition, cause you have 58 types of activities to choose from.

Some words are in swedish, but the only two i think you need to understand is:
omvandla= convert
nollställ= reset
tid= time

Please help me!

Code:

<!-- RINGESON STEG-KONVERTERARE -->

<!-- Följande ska läggas i HEAD-delen -->

<script language="JavaScript" type="text/javascript">
<!-- Copyright 2010, Dennis Guldstrand -->
<!-- dennis@gstrand.net      http://www.gstrand.net -->

<!--
function omvandla() {
var c1 = document.stegKalkylator.tid.value;

 if (document.stegKalkylator.cchoice.selectedIndex == 1) { document.stegKalkylator.result.value = Math.round(c1 * 198; }

 if (document.stegKalkylator.cchoice.selectedIndex == 2) { document.stegKalkylator.result.value = Math.round(c1 * 170; }

 if (document.stegKalkylator.cchoice.selectedIndex == 3) { document.stegKalkylator.result.value = Math.round(c1 * 163; }

 if (document.stegKalkylator.cchoice.selectedIndex == 4) { document.stegKalkylator.result.value = Math.round(c1 * 198; }

 if (document.stegKalkylator.cchoice.selectedIndex == 5) { document.stegKalkylator.result.value = Math.round(c1 * 60; }

 if (document.stegKalkylator.cchoice.selectedIndex == 6) { document.stegKalkylator.result.value = Math.round(c1 * 95; }

 if (document.stegKalkylator.cchoice.selectedIndex == 7) { document.stegKalkylator.result.value = Math.round(c1 * 73; }

 if (document.stegKalkylator.cchoice.selectedIndex == 8) { document.stegKalkylator.result.value = Math.round(c1 * 146; }

 if (document.stegKalkylator.cchoice.selectedIndex == 9) { document.stegKalkylator.result.value = Math.round(c1 * 170; }

 if (document.stegKalkylator.cchoice.selectedIndex == 10) { document.stegKalkylator.result.value = Math.round(c1 * 154; }

 if (document.stegKalkylator.cchoice.selectedIndex == 11) { document.stegKalkylator.result.value = Math.round(c1 * 163; }

 if (document.stegKalkylator.cchoice.selectedIndex == 12) { document.stegKalkylator.result.value = Math.round(c1 * 73; }

 if (document.stegKalkylator.cchoice.selectedIndex == 13) { document.stegKalkylator.result.value = Math.round(c1 * 171; }

 if (document.stegKalkylator.cchoice.selectedIndex == 14) { document.stegKalkylator.result.value = Math.round(c1 * 73; }

 if (document.stegKalkylator.cchoice.selectedIndex == 15) { document.stegKalkylator.result.value = Math.round(c1 * 146; }

 if (document.stegKalkylator.cchoice.selectedIndex == 16) { document.stegKalkylator.result.value = Math.round(c1 * 107; }

 if (document.stegKalkylator.cchoice.selectedIndex == 17) { document.stegKalkylator.result.value = Math.round(c1 * 95; }

 if (document.stegKalkylator.cchoice.selectedIndex == 18) { document.stegKalkylator.result.value = Math.round(c1 * 180; }

 if (document.stegKalkylator.cchoice.selectedIndex == 19) { document.stegKalkylator.result.value = Math.round(c1 * 235; }

 if (document.stegKalkylator.cchoice.selectedIndex == 20) { document.stegKalkylator.result.value = Math.round(c1 * 214; }

 if (document.stegKalkylator.cchoice.selectedIndex == 21) { document.stegKalkylator.result.value = Math.round(c1 * 171; }

 if (document.stegKalkylator.cchoice.selectedIndex == 22) { document.stegKalkylator.result.value = Math.round(c1 * 175; }

 if (document.stegKalkylator.cchoice.selectedIndex == 23) { document.stegKalkylator.result.value = Math.round(c1 * 86; }

 if (document.stegKalkylator.cchoice.selectedIndex == 24) { document.stegKalkylator.result.value = Math.round(c1 * 230; }

 if (document.stegKalkylator.cchoice.selectedIndex == 25) { document.stegKalkylator.result.value = Math.round(c1 * 96; }

 if (document.stegKalkylator.cchoice.selectedIndex == 26) { document.stegKalkylator.result.value = Math.round(c1 * 176; }

 if (document.stegKalkylator.cchoice.selectedIndex == 27) { document.stegKalkylator.result.value = Math.round(c1 * 163; }

 if (document.stegKalkylator.cchoice.selectedIndex == 28) { document.stegKalkylator.result.value = Math.round(c1 * 225; }

 if (document.stegKalkylator.cchoice.selectedIndex == 29) { document.stegKalkylator.result.value = Math.round(c1 * 278; }

 if (document.stegKalkylator.cchoice.selectedIndex == 30) { document.stegKalkylator.result.value = Math.round(c1 * 73; }

 if (document.stegKalkylator.cchoice.selectedIndex == 31) { document.stegKalkylator.result.value = Math.round(c1 * 179; }





 if (document.stegKalkylator.cchoice.selectedIndex == 32) { document.stegKalkylator.result.value = Math.round(c1 * 217; }

 if (document.stegKalkylator.cchoice.selectedIndex == 33) { document.stegKalkylator.result.value = Math.round(c1 * 215; }

 if (document.stegKalkylator.cchoice.selectedIndex == 34) { document.stegKalkylator.result.value = Math.round(c1 * 56; }

 if (document.stegKalkylator.cchoice.selectedIndex == 35) { document.stegKalkylator.result.value = Math.round(c1 * 85; }

 if (document.stegKalkylator.cchoice.selectedIndex == 36) { document.stegKalkylator.result.value = Math.round(c1 * 110; }

 if (document.stegKalkylator.cchoice.selectedIndex == 37) { document.stegKalkylator.result.value = Math.round(c1 * 94; }

 if (document.stegKalkylator.cchoice.selectedIndex == 38) { document.stegKalkylator.result.value = Math.round(c1 * 171; }

 if (document.stegKalkylator.cchoice.selectedIndex == 39) { document.stegKalkylator.result.value = Math.round(c1 * 218; }

 if (document.stegKalkylator.cchoice.selectedIndex == 40) { document.stegKalkylator.result.value = Math.round(c1 * 146; }

 if (document.stegKalkylator.cchoice.selectedIndex == 41) { document.stegKalkylator.result.value = Math.round(c1 * 163; }

 if (document.stegKalkylator.cchoice.selectedIndex == 42) { document.stegKalkylator.result.value = Math.round(c1 * 249; }

 if (document.stegKalkylator.cchoice.selectedIndex == 43) { document.stegKalkylator.result.value = Math.round(c1 * 110; }

 if (document.stegKalkylator.cchoice.selectedIndex == 44) { document.stegKalkylator.result.value = Math.round(c1 * 153; }

 if (document.stegKalkylator.cchoice.selectedIndex == 45) { document.stegKalkylator.result.value = Math.round(c1 * 240; }

 if (document.stegKalkylator.cchoice.selectedIndex == 46) { document.stegKalkylator.result.value = Math.round(c1 * 126; }

 if (document.stegKalkylator.cchoice.selectedIndex == 47) { document.stegKalkylator.result.value = Math.round(c1 * 225; }

 if (document.stegKalkylator.cchoice.selectedIndex == 48) { document.stegKalkylator.result.value = Math.round(c1 * 145; }

 if (document.stegKalkylator.cchoice.selectedIndex == 49) { document.stegKalkylator.result.value = Math.round(c1 * 142; }

 if (document.stegKalkylator.cchoice.selectedIndex == 50) { document.stegKalkylator.result.value = Math.round(c1 * 86; }

 if (document.stegKalkylator.cchoice.selectedIndex == 51) { document.stegKalkylator.result.value = Math.round(c1 * 147; }

 if (document.stegKalkylator.cchoice.selectedIndex == 52) { document.stegKalkylator.result.value = Math.round(c1 * 126; }

 if (document.stegKalkylator.cchoice.selectedIndex == 53) { document.stegKalkylator.result.value = Math.round(c1 * 197; }

 if (document.stegKalkylator.cchoice.selectedIndex == 54) { document.stegKalkylator.result.value = Math.round(c1 * 249; }

 if (document.stegKalkylator.cchoice.selectedIndex == 55) { document.stegKalkylator.result.value = Math.round(c1 * 188; }

 if (document.stegKalkylator.cchoice.selectedIndex == 56) { document.stegKalkylator.result.value = Math.round(c1 * 146; }

 if (document.stegKalkylator.cchoice.selectedIndex == 57) { document.stegKalkylator.result.value = Math.round(c1 * 111; }

 if (document.stegKalkylator.cchoice.selectedIndex == 58) { document.stegKalkylator.result.value = Math.round(c1 * 60; }



 if (document.stegKalkylator.cchoice.selectedIndex == 0) { alert('Du måste välja vad du vill konvertera till steg') }

 if (c1 == "") { alert('Inmatning ej korrekt'); }

if (document.stegKalkylator.result.value == "NaN") { alert('Du måste skriva in en siffra'); }
 }

//-->
</script>








<!-- Detta ska läggas i BODY-delen -->

<form name="stegKalkylator">
<table border="0" cellpadding="4" cellspacing="0" bgcolor="#cccccc">
 <tr>
  <td><font face="verdana, arial, helvetica, sans-serif" size="1">
    Input: <input type="text" size="4" name="tid" style="font-size: 9pt" />
    <select name="cchoice" style="font-size: 9pt">
      <option value="0" selected>Välj...</option>
      <option value="1">Aerobics</option>
      <option value="2">Badminton</option>
      <option value="3">Basket</option>
     
      <option value="4">Bergsklättring</option>
      <option value="5">Biljard</option>
      <option value="6">Bordtennis</option>
      <option value="7">Bowling</option>

      <option value="8">Boxning</option>
      <option value="9">Crosstraining</option>
      <option value="10">Cykling</option>
      <option value="11">Dykning</option>

      <option value="12">Fiska</option>
      <option value="13">Fotboll</option>
      <option value="14">Frisbee</option>
      <option value="15">Fäktning</option>

      <option value="16">Golf</option>
      <option value="17">Gymnastik</option>
      <option value="18">Handboll</option>
      <option value="19">Hockey</option>

      <option value="20">Inlinesåkning</option>
      <option value="21">Innebandy</option>
      <option value="22">Joggning</option>
      <option value="23">Jollesegling/vindsurning</option>

      <option value="24">Kampsport</option>
      <option value="25">Kanoting</option>
      <option value="26">Längdskidåkning</option>
      <option value="27">Längdskidskoåkning</option>

      <option value="28">Löpning lugn</option>
      <option value="29">Löpning snabb</option>
      <option value="30">Minigolf</option>
      <option value="31">Motionscykling normalt</option>
     
      <option value="32">Motionscykling snabb</option>
      <option value="33">Orientering</option>
      <option value="34">Promenad lugn</option>
      <option value="35">Promenad vanlig</option>

      <option value="36">Promenad snabb</option>
      <option value="37">Ridning</option>
      <option value="38">Roddmaskin</option>
      <option value="39">Rugby</option>

      <option value="40">Simma lugn</option>
      <option value="41">Simma vanlig</option>
      <option value="42">Simma snabbt</option>
      <option value="43">Slalom</option>

      <option value="44">Snöskottning</option>
      <option value="45">Spinning</option>
      <option value="46">Square dance</option>
      <option value="47">Squash</option>

      <option value="48">Stavgång</option>
      <option value="49">Styrketräning</option>
      <option value="50">Sällskapsdans lugn</option>
      <option value="51">Sällskapsdans snabb</option>

      <option value="52">Tennis</option>
      <option value="53">Trampmaskin</option>
      <option value="54">Vattenpolo</option>
      <option value="55">Vattengymnastik</option>

      <option value="56">Vattenskidor</option>
      <option value="57">Volleyboll</option>
      <option value="58">Yoga</option>


    </select>&nbsp;</font>
  </td>
  <td align="center" rowspan="3" width="90">
    <input type="button" value="Omvandla" name="it" onClick="omvandla()" style="font-size: 9pt" /><br />
    <input type="reset" value="Nollställ" onClick="reset()" style="font-size: 9pt" />
  </td>
  <td rowspan="3">
    <input type="text" name="result" size="8" />
  </td>
 </tr>
</table>
</form>


Philip M 04-21-2010 10:52 AM

Throughout - missing closing bracket:-

if (document.stegKalkylator.cchoice.selectedIndex == 1) { document.stegKalkylator.result.value = Math.round(c1 * 198 ) ; }

I understand Motionscykling but what is the Swedish for Underwater Motorcycling? :D
I might have a go at Snöskottning - sounds erotic! :D

Instructions on a Swedish chainsaw -- "Do not attempt to stop chain with your hands or genitals."

Goldex 04-21-2010 10:59 AM

Quote:

Originally Posted by Philip M (Post 946604)
Throughout - missing closing bracket:-

if (document.stegKalkylator.cchoice.selectedIndex == 1) { document.stegKalkylator.result.value = Math.round(c1 * 198 ) ; }

I understand Motionscykling but what is the Swedish for Underwater Motorcycling? :D
I might have a go at Snöskottning - sounds erotic! :D

Instructions on a Swedish chainsaw -- "Do not attempt to stop chain with your hands or genitals."

haha, my god i feel stupid. Thanks.
Motionscykling= biking as workout
snöskottning: snowshuffling
:D very erotic

Philip M 04-21-2010 11:03 AM

Quote:

Originally Posted by Goldex (Post 946608)
haha, my god i feel stupid. Thanks.
Motionscykling= biking as workout
snöskottning: snowshuffling
:D very erotic

It is OK, you may call me "Philip". :D

Old Pedant 04-22-2010 02:16 AM

How about this rewrite??
Code:

<script language="JavaScript" type="text/javascript">
<!-- Copyright 2010, Dennis Guldstrand -->
<!-- dennis@gstrand.net      http://www.gstrand.net -->

function omvandla()
{
    var form = document.stegKalkylator;
    var result = null;
    var c1 = form.tid.value;
    if (c1 == "")
    {
        alert('Inmatning ej korrekt');
        result = "???";
    }
    if ( form.cchoice.selectedIndex == 0)
    {
        alert('Du måste välja vad du vill konvertera till steg');
        result = "???";
    }

    var factors = [ 0, 198, 170, 163, 198, 60, 95, 73, 146, 170, 154, 164, 73, 171, 73,
                    146, 107, 95, 180, 235, 214, 171, 175, 86, 230, 96, 176, 163, 225, 278,
                    73, 179, 217, 215, 56, 85, 110, 94, 171, 218, 146, 163, 249, 110, 153,
                    240, 126, 225, 145, 142, 86, 147, 126, 197, 249, 188, 146, 111, 60 ];
    if ( result == null )
    {
        result = Math.round( c1 * factors[form.cchoice.selectedIndex];
        if ( isNaN(result) )
        {
            alert('Du måste skriva in en siffra');
            result = "???";
        }
    }
    form.result.value = result;
}
</script>



All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.