PDA

View Full Version : Multiple "OnClick" functions on a Button


Ne0nE
11-23-2007, 04:22 PM
Hi, need a bit of help. I'm fairly new to javascript and I'm creating a simple website. I have a button as follows:

<input type="button" name="pizzatoppingchoice" value="Price"
OnClick= pizzatoppingcostfunction();>

I want to add another function to this button, I've tried:

<input type="button" name="pizzatoppingchoice" value="Price"
OnClick= pizzatoppingcostfunction(); toppingpricetotal();>

but this does not seem to work. One function displays text into a textbox, and another function displays text into a different textbox on the page. When I put one fucntion in, they both work, but together they don't. Also, by the end I will need about 15 similar functions on this button. I dont see why this isnt possible, and I bet its real simple but I just cant work it out :confused:

Thanks in advance.

abduraooft
11-23-2007, 04:26 PM
Use "" to enclose them.
<input type="button" name="pizzatoppingchoice" value="Price"
onclick= "pizzatoppingcostfunction(); toppingpricetotal();">

Also try to validate your code using w3validator (http://validator.w3.org) to see the rest of such issues!

vwphillips
11-23-2007, 04:27 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function pizzatoppingcostfunction(){
alert('pizzatoppingcostfunction()');
}
function toppingpricetotal(){
alert('toppingpricetotal()');
}
/*]]>*/
</script></head>

<body>
<input type="button" name="pizzatoppingchoice" value="Price"
OnClick= "pizzatoppingcostfunction(); toppingpricetotal();">
</body>

</html>

Ne0nE
11-23-2007, 04:28 PM
I knew it would be something ridiculously simple :p

Thanks for the quick response and the link to the validator