Calling a function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Krandor
    New Member
    • Aug 2008
    • 50

    Calling a function

    I am trying to click a button, call a javascript function with a variable and then parse the result. At this point it is not doing anything.

    What am I doing wrong?


    [CODE=javascript]<script language="javas cript">

    function makeBread(abc) {
    If (String(abc)==" 1") {
    alert("Bread's Done!:1");
    }
    If (String(abc)==" 2") {
    alert("Bread's Done!:2");
    }
    }
    </script>

    <body>
    <input type="button" onClick="javasc ript:makeBread( '1');" value="Done">
    </body>[/CODE]
    Last edited by gits; Sep 3 '08, 08:34 PM. Reason: fix code tags usage
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I would omit the String() function since datatypes are converted as you need them.

    maybe you want to use switch() instead of 2 if's.

    what about an event handler like addEventListene r()/attachEvent()?

    regards

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5388

      #3
      1. javascript is case-sensitive and therefor:

      Code:
      If
      must be

      Code:
      if
      otherwise you will get an error because the interpreter 'thinks' you are calling a custom function If() since it is not a keyword.

      now it should work with the change, but:

      2. the language attribute is deprecated so you should use:

      [CODE=html]<script type="text/javascript">
      [/CODE]
      and

      3. the following:

      [CODE=html]<input type="button" onClick="javasc ript:makeBread( '1');" value="Done">
      [/CODE]
      should be:

      [HTML]<input type="button" onclick="makeBr ead('1');" value="Done">
      [/HTML]
      according to the specs.

      kind regards

      Comment

      Working...