...

View Full Version : Two functions, one "onClick"



Twitch2k7
06-12-2008, 06:51 PM
<html>
<head>
<script type="text/javascript">
function calcbase(calc,attack){
if(document.calc.attack.value=='tackle'){
document.calc.dam.value=8.75
}
}
function calcstab(calc,stab){
if(document.calc.stab.value=='yes'){
document.calc.dam.value*=1.5
}
}
</script>
</head>
<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="calcbase(calc,attack);calcstab(calc,stab)">Calculate</button></td>
<td><input type="text" value="damage" name="dam" readonly="readonly" /></td>
</tr>
</table>
</form>
</body>
</html>


I heard you were able to use two functions in one onClick by separating them with a semicolon. Now I've done that, yet it only carries out one function, the calcbase(calc,attack) one. Anybody mind lending me some help?

vwphillips
06-12-2008, 07:30 PM
<html>
<head>
<script type="text/javascript">
function calcbase(calc,attack){
if(document.calc.attack.value=='tackle'){
document.calc.dam.value=8.75;
}
}
function calcstab(calc,stab){
if(document.calc.stab.value=='yes'){
document.calc.dam.value*=1.5;
}
}
</script>
</head>
<body>
<form name="calc">
<table border="1">
<tr>
<td>Attack</td><td><input type="text" name="attack" value="tackle"/>
</tr>
<tr>
<td>STAB?</td>
<td>
<select name="stab">
<option value="0">--
<option selected="selected" value="yes">Yes
<option value="no">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="calcbase(calc,attack);calcstab(calc,stab)">Calculate</button></td>
<td><input type="text" value="damage" name="dam" readonly="readonly" /></td>
</tr>
</table>
</form>
</body>
</html>

Twitch2k7
06-12-2008, 07:53 PM
I was missing a semicolon, huh? Seems simple enough. Thanks, a lot.

Twitch2k7
06-12-2008, 08:03 PM
Actually, one more question: Can you have more than two functions on one onClick?

Philip M
06-12-2008, 08:32 PM
Actually, one more question: Can you have more than two functions on one onClick?

Indeed you can. onclick = "function1();function2();function3();function4()"

vwphillips
06-13-2008, 11:38 AM
the dual function call was fine but not the change to the select values to align with the conditional in the function


<select name="stab">
<option value="0">--
<option selected="selected" value="yes">Yes
<option value="no">No
</select>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum