twilitegxa Posted August 24, 2009 Share Posted August 24, 2009 Can anyone tell me why this script isn't working? The calcGroupDiscount function isn't working for some reason. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Central Valley Snowboarding</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="js_styles.css" type="text/css" /> </head> <body> <h1>Central Valley Snowboarding</h1> <h2>Group Reservations</h2> <form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded"> <h3>Snowboarding Date</h3> <p><input type="text" name="reservationDate" /> <a href="" onclick="displayCalendar()">Select Date</a></p> <h3>Group Leader</h3> <table border="0"> <tr valign="top"> <td>Last Name<br /> <input type="text" name="leaderLastName" size="50" /><br /> First Name<br /> <input type="text" name="leaderFirstName" size="50" /><br /> Telephone<br /> <input type="text" name="leaderTelephone" size="50" /><br /> Address<br /> <input type="text" name="leaderAddress" size="50" /><br /> City, State, Zip<br /> <input type="text" name="leaderCity" size="34" /> <input type="text" name="leaderState" size="2" maxlength="2" /> <input type="text" name="leaderZip" size="5" maxlength="5" /></td> </tr></table> <script type="text/javascript"> //get date var dateObject = new Date(); var month = dateObject.getMonth(); var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var dateToday = monthArray[month] + " " + dateObject.getDate() + "," + dateObject.getFullYear(); document.forms[0].reservationDate.value = dateToday; //calculate group discount function calcGroupDiscount(groupsize) { var dailyRate = 49; if (groupSize > 5 && groupSize < 10) dailyRate = 49 / 1.1; else if (groupSize > 10 && groupSize < 25) dailyRate = 49 / 1.2; else if (groupSize > 24) dailyRate = 49 / 1.25; var groupRate = groupSize * dailyRate; document.forms[0].discount.value = groupRate.toFixed(2); } </script> <h3>Group Discounts</h3> <ul> <li>Daily Rate: $49</li> <li>5-10 snowboarders: 10% discount</li> <li>11-24 snowboarders: 20% discount</li> <li>25+ snowboarders: 25% discount</li> </ul> <p>How many snowboarders are in your group? <input type="text" size="5" value="0" onchange="calcGroupDiscount(this.value)"> <br /> Your group rate is: $<input type="text" name="discount" size="60" value="0" readonly="readonly" style="border: none" /></p> <p><input type="submit" value="Submit Group Reservation" /><input type="reset" value="Reset" /></p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
haku Posted August 25, 2009 Share Posted August 25, 2009 There is no 'onchange' for inputs. You need 'onkeyup' or 'onblur' or something else. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 25, 2009 Author Share Posted August 25, 2009 Neither of the ones you suggested worked. :-( I got this code from a tutorial in a book, so are the writers idiots (can't use onchange)? Or did I miss something else? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.