...

View Full Version : onClick If...Else Error



Twitch2k7
06-12-2008, 04:38 PM
<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:


<button type="button" onClick="if(document.calc.attack==tackle){document.calc.dam==3.5}">


Any idea why it isn't working?

abduraooft
06-12-2008, 04:46 PM
Have you missed to specify the value?
<button type="button" onClick="if(document.calc.attack.value=='tackle'){document.calc.dam.value==3.5}">

Twitch2k7
06-12-2008, 04:55 PM
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?

Philip M
06-12-2008, 05:04 PM
<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".

Twitch2k7
06-12-2008, 05:17 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum