Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onClick If...Else Error

    Code:
    <html>
    <body>
    <form name="calc">
    <table border="1">
    <tr>
    <td>Attack</td><td><input type="text" name="attack" />
    </tr>
    <tr>
    <td>STAB?</td>
    <td>
    <select name="stab">
    <option value="0">--
    <option value="1">Yes
    <option value="2">No
    </select>
    </td>
    </tr>
    <tr>
    <td>SE?</td>
    <td>
    <select name="se">
    <option value="0">--
    <option value="1">Yes
    <option value="2">No
    </select>
    </td>
    </tr>
    <tr>
    <td>UE?</td>
    <td>
    <select name="ue">
    <option value="0">--
    <option value="1">Yes
    <option value="2">No
    </select>
    </td>
    </tr>
    <tr>
    <td>NVE?</td>
    <td>
    <select name="nve">
    <option value="0">--
    <option value="1">Yes
    <option value="2">No
    </select>
    </td>
    </tr>
    <tr>
    <td>Critical?</td>
    <td>
    <select name="crit">
    <option value="0">--
    <option value="1">Yes
    <option value="2">No
    </select>
    </td>
    </tr>
    <tr>
    <td><button type="button" onClick="if(document.calc.attack==tackle){document.calc.dam==3.5}">Calculate</button></td>
    <td><input type="text" value="damage" name="dam" readonly="readonly" /></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    I'm having a problem with the following line:
    Code:
    <button type="button" onClick="if(document.calc.attack==tackle){document.calc.dam==3.5}">
    Any idea why it isn't working?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Have you missed to specify the value?
    Code:
    <button type="button" onClick="if(document.calc.attack.value=='tackle'){document.calc.dam.value==3.5}">
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    True, I did forget to specify the value, yet after I did so it still didn't work =/
    Thanks for trying, though. Is there anything else that could be wrong?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    <td><button type="button" onClick="if(document.calc.attack==tackle){document.calc.dam.value = 3.5}">Calculate</button></td>

    tackle is undefined.

    If tackle is supposed to be a literal, then it should be in quotes "tackle".

  • #5
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect. I actually used single quotation marks since they're already within quotations. I also took away one of the equal signs and then it worked. Thanks a lot, both of you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •