PDA

View Full Version : Can you use a "switch" statement inside a Function



Jodman
12-16-2005, 04:28 PM
Is it possible to do the following or is my syntax wrong?


function stopbill(btncode){
switch(btncode)
case "dlp":
window.alert("Stop")
case "dlb":
window.alert("Back")
case "dlf":
window.alert("Next")
}


Here is the HTML code where I call the function.


<div align="right">
<a href="#" id="dlb" onclick="return stopbill('dlb')">
<img src="images/bctrl.gif" alt="Previous" border="0" id="dlbi"/>
</a>
</div>

Thanks!
Jodman

Jodman
12-16-2005, 04:48 PM
I found my error. Please remove this post.

Thanks!
Jodman

Twey
12-16-2005, 04:53 PM
Yes, you missed the braces. You also forgot to "break;" after your code in each case, which you're no doubt going to ask about in a minute.

Jodman
12-16-2005, 06:38 PM
Nope. Did not need to ask, hence the reason I wanted the post deleted. Thanks for the kind response though.

Jodman

Twey
12-16-2005, 06:44 PM
A post shouldn't be deleted if someone can learn from it. If you solve a problem, you ought to say how you solved it, in case someone else has the same.