JavaScript - Fare Calculator - What Is Wrong With This Code?
Code:
<script> // Calculate and display the total cost of the selected cruise function CostOfCruise(findRounding) { //Get the varius elements in the statements and variable document.getelementbyID ("costCruise" + i); //Assign a value to the radioButton document.getElementById("returnFare"); //Assign a vlaue to the checkbox document.getElementById("costSeat" + i); //Assign a value to the second radio button document.getElementById ("totalCost"); //Assign a value to the total cost of the cruise document.getElementById("findRounding"); //Assign a rounded value to the total cost //List the variables involved var radioButton; // A radio button var costCruise; //Cost of each cruise var checkbox; //A checkbox var returnFare; //The reutrn fare var radio; //the second set of radio buttons var costSeat; //Cost of seating choice var totalCost; //The final cost of the cruise //Determine the cruise chosen and its cost //Get the cost of the selected cruise for (var i = 1; i <= 5; i++) radioButton = document.getElementById("Costcruise" + i); // Display the appropriate response if (radioButton.value === "") alert("You need to choose one of the islands to visit."); else (radioButton.checked === true); //Get the cost of the cruise as a whole number costCruise *= parseInt(radioButton.value); //Determine if return fare purchased // Check if the object is valid before attempting to use it if (returnFare.value === null) return; else (checkbox.checked === true); checkbox = document.getElementById("returnFare"); //Get the value of the reutrn fare as a whole number returnFare *= parseInt(checkbox.value); //Determine which type of seating chosen if (radio.value === "") alert("You need to choose your preferred seating arrangements."); else (radio.checked === true); radio = document.getElementById("costSeat" + i); //Get the cost of the seating as a whole number costSeat *= parseFloat(radio.value); //Calculate total cost of cruise totalCost = document.getElementById ("totalCost"); totalCost = ("costCruise" * "returnFare") * "costSeat"; //Total Cost of cruise //rounds the cost to its nearest integer findRounding = document.getElementById("findRounding"); findRounding = Math.round("totalCost"); alert ("The total cost of this cruise is $" + findRounding); } </script> <html> body> <h1>Island Hopper Cruises Fare Calculator</h1> <p> Complete the form below to calculate the cost of your cruise.</p> <form> <!--The choices of islands to visit with their assigned values or cost of the trip.--> <p>Route:<br /> <input type="radio" id="cruise1" name="costCruise" value="49"> <label for="cruise1">Main Beach - Azkaban Island</label><br> <input type="radio" id="cruise2" name="costCruise" value="79"> <label for="cruise2">Main Beach - Amity Island</label><br> <input type="radio" id="cruise3" name="costCruise" value="109"> <label for="cruise3">Main Beach - Treasure Island</label><br> <input type="radio" id="cruise4" name="costCruise" value="89"> <label for="cruise4">Main Beach - Gilligan's Island</label><br> <input type="radio" id="cruise5" name="costCruise" value="59"> <label for="cruise5">Main Beach - Skull Island</label><br></p> <!--The decision to purcahse a return fare or not.--> <p> Click here if you will be purchasing a return fa <input type="checkbox" id="returnFare" name="returnFare" value="2"></p> <!--The choice of seating arrangment and their assigned value according to class of seat.--> <p>Seating:<br /> <input type="radio" id="first" name="costSeat" value="2.5"> <label for="first">First class</label><br> <input type="radio" id="busi" name="costSeat" value="1.5"> <label for="busi">Business class</label><br> <input type="radio" id="econ" name="costSeat" value="1"> <label for="econ">Economy class</label><br></p> <!--The total cost of the chosen trip displayed as an alert.--> <input type="button" value="Calculate" onclick="CostOfCruise"> <input type="reset" value="Reset"> </form> </body> </html> Similar TutorialsI'm trying to get this calculator to work html Code: <form name="Calc" id="calculator" style="position: fixed; top: 25px; right: 5px; background: #5F4A29;" action=""> <table border="6"> <tr> <td colspan="4"><input type="text" name="Input" size="25" onclick="calc(Calc); return true" /></td> </tr> <tr> <td><input class="button" type="button" name="clr" value="c" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="(" value="(" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name=")" value=")" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="equ" value="=" onclick="calc(Calc)" /></td> </tr> <tr> <td><input class="button" type="button" name="_1" value="1" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_2" value="2" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_3" value="3" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="add" value="+" onclick="calc(Calc)" /></td> </tr> </tr> <tr> <td><input class="button" type="button" name="_4" value="4" onclick="calc(Calc) += '4'" /></td> <td><input class="button" type="button" name="_5" value="5" onclick="calc(Calc) += '5'" /></td> <td><input class="button" type="button" name="_6" value="6" onclick="calc(Calc) += '6'" /></td> <td><input class="button" type="button" name="sub" value="-" onclick="calc(Calc)" /></td> </tr> <tr> <td><input class="button" type="button" name="_7" value="7" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_8" value="8" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_9" value="9" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="mul" value="*" onclick="calc(Calc)" /></td> </tr> <tr> <td></td> <td><input class="button" type="button" name="_0" value="0" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="dot" value="." onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="div" value="/" onclick="calc(Calc)" /></td> </tr> </table> </form> and js Code: function calc(Calc) { var add = eval (document.Calc.add.value); var sub = eval (document.Calc.sub.value); var mul = eval (document.Calc.mul.value); var div = eval (document.Calc.div.value); var clr = eval (document.Calc.clr.value); var _0 = eval (document.Calc._0.value); var _1 = eval (document.Calc._1.value); var _2 = eval (document.Calc._2.value); var _3 = eval (document.Calc._3.value); var _4 = eval (document.Calc._4.value); var _5 = eval (document.Calc._5.value); var _6 = eval (document.Calc._6.value); var _7 = eval (document.Calc._7.value); var _8 = eval (document.Calc._8.value); var _9 = eval (document.Calc._9.value); var dot = eval (document.Calc.dot.value); var equ = eval (document.Calc.equ.value) var output=Calc.Input.value=add+sub+mul+div+clr+_0+_1+_2+_3+_4+_5+_6+_7+_8+_9+dot+equ; document.getElementById("calculator").innerHTML=output; } Can someone help me sort this out? Hello! I have a really simple JavaScript calculator I'm running, and for the life of me can not figure out how to solve this crazy number problem. It's not doing the math properly, and javascript is not my strongest suit. All my script does is take user input of numbers into a form field, subtract that from another form and multiply the answer of those two forms by whatever the user put in. Example: 210 (minus) 120 (multiplied by) .90 = 81 Here is the actual script: Code: // Calculator function CalculateSum(Atext, Btext, Ctext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); form.Answer.value = A - B * C; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> And the html I am using: Code: <form name="Calculator" method="post"> <p>Base Average<input type=text name="input_A"></p> <p>Current Average:<input type=text name="input_B"></p> <p>Percentage of:<input type=text name="input_C"></p> <p>Your ball speed is: (miles per hour) <input name="Answer" type=text readonly> </p> <p> <input type="button" value="Calculate Handicap" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form)"> <input type="button" value="Clear" name="ClearButton" onClick="ClearForm(this.form)"> </p> </form> Any help would be greatly appreciated! The question in the book says: Many companies normally charge a shipping and handling fee for purchases. Create a Web page that allows a user to enter a purchase price into a text box; include a JavaScript function that calculates shipping and handling. Add functionality to the script that adds a minimum shipping and handling fee of $1.50 for any purchase that is less than or equal to $25.00. For any orders over $25.00, add 10% to the total purchase price for shipping and handling, but do not include the $1.50 minimum shipping and handling fee. The formula for calculating a percentage is price*percent/100. After you determine the total cost of the order (purchase plus shipping and handling), display it in an alert dialog box. This is what I have so far, it comes up with the text box, but when the price is entered it doesn't come back with an answer. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="js_styles.css" type="text/css" /> <title>Calculating Shipping & Handling</title> <script type="text/javascript"> /* ![CDATA[ */ function getShipping(); { if (price <= 25.00) shipping = 1.50 else if(price > 25.00) shipping = (price * (10/100)); } /* ]]> */ </script> </head> <body> <script type="text/javascript"> /* ![CDATA[ */ document.write("<h1>Purchase Price with Shipping</h1>"); /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ var price=prompt("What is your purchase price?"); getShipping(); document.write ("<p>The purchase price entered is $" + (price) + "</p>"); document.write ("<p>Shipping is $" + (shipping) + "</p>"); var total = price + shipping; document.write("Your total price with shipping is $ " + (total) + ""); /* ]]> */ </script> </body> </html> Hi All, I need a code for my online blind shop so that customers can get a quote without having to go through the order process. They would need to enter their fabric range, style and width and drop. My first obsticle is where to start learning how to do it! Could anyone please point me in the direction of a good but easy to understand tutorial or advise me on how I can achieve my goal? I've looked all over the internet but cant find what I am looking for. I'm willing to learn and do this myself, otherwise I'll have to pay for someone else to do it for me. Any help would be great! Thanks, Deb. Hello, if you could please tell me what I did wrong to make this code not work. Can you put a variable in a function callback ? Quote: <script type="text/javascript"> var aaa = prompt('number?') var obja = new Const(aaa); functin Const(numb){ this.x=numb; alert(obja.x); } </script> Could someone please tell me why this doesn't work??? <html> <head> <title>slideshow</title> </head> <body> <script type="text/javascript"> theimage = new Array(); // The dimensions of ALL the images should be the same or some of them may look stretched or reduced in Netscape 4. // Format: theimage[...]=[image URL, link URL, name/description] theimage[0]=["http://img844.imageshack.us/img844/981/img3small.jpg", length="380", width="380"]; theimage[1]=["http://img850.imageshack.us/img850/4371/img2small.gif", length="380", width="380"]; theimage[2]=["http://img191.imageshack.us/img191/2923/img1small.gif", length="380", width="380"]; ///// Plugin variables playspeed=3000;// The playspeed determines the delay for the "Play" button in ms dotrans=1; // if value = 1 then there are transitions played in IE transtype='blendTrans';// 'blendTrans' or 'revealtrans' transattributes='23';// duration=seconds,transition=#<24 //##### //key that holds where in the array currently are i=0; //########################################### window.onload=function(){ //preload images into browser preloadSlide(); //set transitions GetTrans(); //set the first slide SetSlide(0); //autoplay PlaySlide(); } //########################################### function SetSlide(num) { //too big i=num%theimage.length; //too small if(i<0)i=theimage.length-1; //switch the image if(document.all&&!window.opera&&dotrans==1)eval('document.images.imgslide.filters.'+transtype+'.Appl y()') document.images.imgslide.src=theimage[i][0]; if(document.all&&!window.opera&&dotrans==1)eval('document.images.imgslide.filters.'+transtype+'.Play ()') } //########################################### function PlaySlide() { if (!window.playing) { PlayingSlide(i+1); if(document.slideshow.play){ document.slideshow.play.value=" Stop "; } } else { playing=clearTimeout(playing); if(document.slideshow.play){ document.slideshow.play.value=" Play "; } } // if you have to change the image for the "playing" slide if(document.images.imgPlay){ setTimeout('document.images.imgPlay.src="'+imgStop+'"',1); imgStop=document.images.imgPlay.src } } //########################################### function PlayingSlide(num) { playing=setTimeout('PlayingSlide(i+1);SetSlide(i+1);', playspeed); } //########################################### //desc: picks the transition to apply to the images function GetTrans() { //si=document.slideshow.trans.selectedIndex; if((document.slideshow.trans && document.slideshow.trans.selectedIndex == 0) || (!document.slideshow.trans && dotrans==0)){ dotrans=0; } else if ((document.slideshow.trans && document.slideshow.trans.selectedIndex == 1) || (!document.slideshow.trans && transtype == 'blendTrans')){ dotrans=1; transtype='blendTrans'; document.imgslide.style.filter = "blendTrans(duration=1,transition=1)"; }else{ dotrans=1; transtype='revealtrans'; if(document.slideshow.trans) transattributes=document.slideshow.trans[document.slideshow.trans.selectedIndex].value; document.imgslide.style.filter = "revealTrans(duration=1,transition=" +transattributes+ ")"; } } //########################################### function preloadSlide() { for(k=0;k<theimage.length;k++) { theimage[k][0]=new Image().src=theimage[k][0]; } } </script> <form name="slideshow"> <table style="width: 502px; height: 358px;" border="1" cellpadding="2" cellspacing="0"> <tbody> <tr> <td align="center"> <a href="#" onmouseover="this.href=theimage[i][1];return false"> <script type="text/javascript"> document.write('<img name="imgslide" id="imgslide" src="'+theimage[0][0]+'" border="0">') </script></a></td> </tr> </tbody> </table> </form> </body> </html> So this is suppose to scrape a page and take data from it and put it in a text box on my web page. This is the web page that I'm taking the info from, https://147.241.62.30/4dwxPortal/web/191/7, and here is a link to the source code I have pulled up from IE Developer Tools: http://i1228.photobucket.com/albums/...h/scraper2.jpg here is my code: Code: <script type="text/javascript"> function temperature(theTemp){ var config = <config> <var-def name="stats"> <html-to-xml> <http method="get" url="https://147.241.62.30/4dwxPortal/web/191/7"/> </html-tosml> </var-def> </config>; var s = new scraper(config); var html = new XML(s.stats.substring(s.stats.indexof("?>") + 2)); var downloads = html.body.div.div.(div[2]).div.div.div.div.section.div.div.div.form.div.table.tbody.tr.(td[2]).div.table.tbody.tr.td.div.toString(); theTemp.value = downloads; } </script> I get an error in the HTML code saying that it expects an object. here is the code where I call the function: Code: <html> <body> <input id="Button61" type="button" value="Calculate" style=" Width:110px; position:absolute; left:4.65in;" onclick="temperature(document.getElementById('TextBox313'))" /> </body> <html> What am I doing wrong? I watched what the guy did on youtube http://www.youtube.com/watch?v=-E67f0TqsDY to write this, either something is wrong with my javascript or I'm calling the text in the website wrong or both... Hi, I've got an html page that has it's overflow hidden with integrated css, now I want to use javascript to set overflow to hidden as soon as an swf is finished. My code is function hidelayer(lay) { document.getElementByName('body').style.overflow = 'visible'; } and I'm calling this function from flash with: getURL("javascript:hidelayer('newlayer');"); in the last frame. But the overflow stays hidden, so apparantly my javascript is wrong. The overflow is set to hidden in the body tag btw. Can anyone help me? Code: <script type="text/javascript"> function validatePassword() { var strInput //Request user enter their password then check its validity strInput = prompt("Enter your password to check it's validity",""); while (!(strInput.length() >= 7 && strInput.indexOf('*') >=0 0 && (strInput.charAt(0) =+ 'Z')) { alert("Your password is invalid, \n Please try again") strInput = prompt("Enter your password to check it's validity",""); } //Outcome if password is valid alert("Your password is valid") //End while } </script> There is an issue with the while statement that stops it from working, but i fail to see what. need a second pair of eyes In my table i have search functionality based dropdown values. when i do search "Opportunity" from dropdown, it always goes to "Organization" page. because, in onsubmit the value comes as "ozSlsCustomerQuickFind.jsp" that's why the "action" is always comes as "ozSlsCustomerQuickFind.jsp" instead of search value. Here is the code for the dropdown values and search button. Code: buf.append( "<table cellspacing=0 cellpadding=1 border=0 align=left>" ); buf.append( "<tr><td class=verySmall align=left>" ); buf.append( " <form name=QF id=QF action=\"ozSlsCustomerQuickFind.jsp\" method=post onSubmit=\"Javascript:document.QF.action=document.QF.searchDest.options[document.QF.searchDest.selectedIndex].value;\">" ); buf.append( " <input class=textInputSmall type=text name=quickFindText value=\"\">" ); buf.append( " <select name=\"searchDest\" id=\"searchDest\" class=textInputSmall>" ); buf.append( " <option value=\"ozSlsCustomerQuickFind.jsp\" "+(cat.startsWith("CUSTOMER")?"selected":"")+">"+_p.get("organization") ); buf.append( " <option value=\"ozSlsContactQuickFind.jsp\" "+(cat.startsWith("CONTACT")?"selected":"")+">"+_p.get("contact") ); buf.append( " <option value=\"ozSlsOppQuickFind.jsp\" "+(cat.startsWith("OPP")?"selected":"")+">"+_p.get("opportunity") ); buf.append( " <option value=\"ozCalTaskQuickFind.jsp\" "+(cat.startsWith("TASK")?"selected":"")+">"+_p.get("task") ); buf.append( " </select>" ); buf.append( "<input class=\"smallButton\" type=submit name=go value="+_p.get("search")+">" ); buf.append( "</td><td></form></td></tr>" ); buf.append( "</table>" ); Can anybody give an idea on this ? Hi In my form i have delete Image. When i click on that image needs to delete the related record. I wrote this the following logic when i click on the image, it is not invoking the onClick logic. is there any syntax wrong in this logic. Acutally before adding this schId Code: schId='<%=cs.getTmpl().getID()%> the form logic is calling. but after i add schId , it's not calling . Code: <td class=ppolSmallText align="right" width="85%" nowrap><img src="graphics/ozIcon12Del.gif" onClick="document.displaySchedule.elements['ahsFormAction'].value='delSchedule&schId='<%=cs.getTmpl().getID()%>;document.displaySchedule.submit();"></td> Please give me an Idea on this ?? Code: function CalculatePayment(form) { // Check Amount is not a number if (isNaN(form.CheckAmount.value) || form.CheckAmount.value=="") { alert("Please enter a valid check amount."); form.CheckAmount.select(); form.CheckAmount.focus(); return; } else { form.CheckAmount.value = moneyConvert(form.CheckAmount.value); } var totalMoney = parseFloat(form.CheckAmount.value); var copayDue = parseFloat(form.CopayDue.value); var deductibleDue = parseFloat(form.DeductibleDue.value); var totalDue = parseFloat(form.TotalDue.value); // COPAY if (totalMoney > copayDue) { form.Copay.value = moneyConvert(copayDue); totalMoney = (totalMoney - copayDue); } else { form.Copay.value = moneyConvert(totalMoney); totalMoney = 0; } // DEDUCTIBLE if (totalMoney > deductibleDue) { form.Deductible.value = moneyConvert(deductibleDue); totalMoney = (totalMoney - deductibleDue); } else { form.Deductible.value = moneyConvert(totalMoney); totalMoney = 0; } var copay = parseFloat(form.Copay.value); var deductible = parseFloat(form.Deductible.value); // COPAY ADJUSTMENT if (form.FullPay.checked) form.CopayAdjustment.value = moneyConvert(copayDue - copay); else form.CopayAdjustment.value = "0.00"; // DEDUCTIBLE ADJUSTMENT if (form.FullPay.checked) form.DeductibleAdjustment.value = moneyConvert(deductibleDue - deductible); else form.DeductibleAdjustment.value = "0.00"; // OVERPAY form.Overpay.value = moneyConvert(totalMoney); } function convertMoneyCents(txt) { if (!isNaN(txt.value)) { txt.value = moneyConvert(txt.value); } } function DoCal(szTarget, szFieldLabel) { var szDate = window.showModalDialog("../Calendar.html",szFieldLabel,"dialogHeight:230px;dialogWidth:220px;;center=1;status=0"); if((szDate != "") && (szDate != "undefined")) { szTarget.value = szDate; } } function moneyConvert(strval) { strval = Math.abs(strval) + ""; if (strval.indexOf(".") == -1) { strval = strval + '.00'; } else { strval = strval + "00"; strval = strval.substr(0, strval.indexOf(".") + 3); } return strval; } HTML Code: <!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"> <head> <title>patientCalc</title> <link href="patientCalc.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="patientCalc.js"></script> </head> <body> <form id="frmPayment" action=""> <p> Total Balance: <input type="text" id="TotalDue" value="125.25" /> </p> <p> Total CoPay: <input type="text" id="CopayDue" value="114.54" /> </p> <p> Total Deductible: <input type="text" id="DeductibleDue" value="10.71" /> </p> <p> Original Total: <input type="text" id="OriginalTotal" value="125.25" disabled="disabled" /> </p> <p> Check Amount: <input type="text" id="CheckAmount" /> </p> <p> Copay: <input type="text" id="Copay" /> </p> <p> Deductible: <input type="text" id="Deductible" /> </p> <p> Pay in Full: <input type="checkbox" id="FullPay" checked="checked" /> </p> <p> Copay Adjustment: <input type="text" id="CopayAdjustment" /> </p> <p> Deductible Adjustment: <input type="text" id="DeductibleAdjustment" /> </p> <p> Overpay: <input type="text" id="Overpay" /> </p> <p> <input type="button" value="Calculate Payment" onclick="CalculatePayment(document.forms[0]);" /> </p> </form> </body> </html> the Deductible keeps coming up 0.00 Simply what is wrong with my code. The following code is for a simple slideshow that is supposed to accept a range of images to display. Its for a website where it shows all the store for a company and when you rollover the image of it is plays a slideshow of images. If you have any other way of doing this that would be easier than please post it here. It must work in all browsers. As you can see there are lots of images to me loaded for this Code: <!-- var image1=new Image() image1.src="contact/images/wingham/01.jpg" var image2=new Image() image2.src="contact/images/wingham/02.jpg" var image3=new Image() image3.src="contact/images/wingham/03.jpg" var image4=new Image() image4.src="contact/images/wingham/04.jpg" var image5=new Image() image5.src="contact/images/wingham/05.jpg" var image6=new Image() image6.src="contact/images/wingham/06.jpg" var image7=new Image() image7.src="contact/images/listowel/01.jpg" var image8=new Image() image8.src="contact/images/listowel/02.jpg" var image9=new Image() image9.src="contact/images/listowel/03.jpg" var image10=new Image() image10.src="contact/images/listowel/04.jpg" var image11=new Image() image11.src="contact/images/listowel/05.jpg" var image12=new Image() image12.src="contact/images/listowel/06.jpg" var image13=new Image() images13.src="contact/images/hanover/01.jpg" var image14=new Image() images14.src="contact/images/hanover/02.jpg" var image15=new Image() images15.src="contact/images/hanover/03.jpg" var image16=new Image() images16.src="contact/images/hanover/04.jpg" var image17=new Image() images17.src="contact/images/hanover/05.jpg" //--> <!-- //variable that will increment through the images var step=1 function slideit(start,finish,action){ if(action == 'abort'){ return } //if browser does not support the image object, exit. if (!document.images) return document.images.slide.src=eval("image"+step+".src") if (step<finish){ step++ } else{ step=start } //call function "slideit()" every 2.5 seconds timer = setTimeout("slideit(start,finish)", 1000); } function slideOff() { document.images.slide.src=eval("image1.src") clearTimeout(timer); } //Called something like this: slideit(1,6)// OK I am stumped. I am creating a little html to check my js file. I want to have the user enter two parameters and then call the function using those two paramaters and then display the answer on the screen. Here is the html file <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>HomeWork3</title> <script type="text/JavaScript" src="grosspay.js"> </script> </head> <body> <script type="text/javascript"> <![CDATA[ var hoursWorked = parseInt(prompt("Enter the Number of Hours You Worked", "40")); var hourlyRate = parseInt(prompt("Enter the Number of Hours You Worked", "10")); function grossPay(hoursWorked, hourlyRate){ document.writeln(grossPay + " Is your normal amount of your check before taxes are taken out"); } ]]> </script> </body> </html> Here is the JS file function grossPay (hoursWorked, hourlyRate) { if (hoursWorked > 40){ var overTimeHrs = (hoursWorked - 40) var overTimePay = (overTimeHrs * 1.5 * hourlyRate) var regPay = (40 * hourlyRate) var grossPay = regPay + overTimePay return grossPay }else { var grossPay = (40 * hourlyRate) return grossPay} } CAN SOMEONE PLEASE HELP Ok, the code below works ok in Firefox but not in IE and I can't figure out why. Please note that when I include the movie src in the body tag, the way it is in the code below, the movie loads fine but the window does not resize as it should (see the document.getElementByID). When I take the movie src out of the body tag however, it doesn't load. It's supposed to load just from the javascript meaning the src shouldn't need to be in the body for this to work. Can anyone see what the problem is? Code: <html> <head> <style type="text/css"> <!-- .fontStyle { font-family: Verdana, Geneva, sans-serif; font-size: small; font-weight: bold; color: #67A2DC; } --> </style> <script type="text/javascript"> /*window.onload=function(){ loadVideo(); } /* function wait() { //loadVideo(); setTimeOut("loadVideo()", 2000); } */ function loadVideo() { <!-- if (parseInt(navigator.appVersion)>3) { if (navigator.appName == "Netscape") { winW = window.innerWidth; winH = window.innerHeight; } if (navigator.appName.indexOf("Microsoft") != -1) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } } var dimW = winW-50; var dimH = winH-20; var w1 = dimW.toString(); var h1 = dimH.toString(); if(document.getElementById("vidEmbed") != null) { document.getElementById("vidEmbed").src = "oracleWelcome_1.wmv"; document.getElementById("vidEmbed").style.width = w1; document.getElementById("vidEmbed").style.height = h1; } else if(document.getElementById("Player") != null) { document.getElementById("Player").style.width = w1; document.getElementById("Player").style.height = h1; document.getElementById("objectSrc").value = "oracleWelcome_1.wmv"; } } </script> </head> <body><div> <p><span class="fontStyle">Introduction<br> </span> <object id="Player" width="100%" height="100%" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="border:0px;"> <param name="autoStart" value="True"> <param name="uiMode" value="full"> <param name="volume" value="50"> <param name="mute" value="false"> <param name="URL" id="objectSrc" value=""> <embed src="" id="vidEmbed" width="100%" height="100%" autostart="true" uimode="full" volume="50" mute="false"> </embed> </object> </p><body onload="loadVideo();"></body> </div> </body> </html> ok i am trying to make a countdown timer from 20 seconds when i click start where am i going wrong with this Code: <html> <head> </head> <body> <script type="text/javascript"> function timer() { var milisec=0 var seconds=20 document.counter.d2.value=20 function display() { if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1){ milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",100) display() }} </script> <form name="counter"> <center> Text Timer<br> <input type="text" size="30" name="d2"> <br> <input type="button" onclick="timer()" value="click me to start"> </center> </form> </body> </html> sorry i think this is in the wrong section...how do i remove I am trying to validate the form on my site using an external js file. Here is the HTML for my form: <form method="post" form action="sendmail.asp"> <p><label for="emailAddr">Email Address: <input id="emailAddr" name="emailAddr" type="text" size="30" class="reqd email" /> </label></p> <p><span id="spryselect1"> <label for="Players">Players: <select id="player" class="reqd" name="player"> <option value="" selected="selected">Choose a Player</option> <option value="Woodson">Charles Woodson</option> <option value="Rodgers">Aaron Rodgers</option> <option value="Driver">Donald Driver</option> <option value="Hawk">A.J. Hawk</option> <option value="Barnett">Nick Barnett</option> <option value="Bigby">Atari Bigby</option> </select> </label> <span class="selectRequiredMsg">Please select an item.</span></span></p> <p><label for"options"> Size(default is X-Large): <label for="medium"><input type="checkbox" name="options" id="medium" value="Medium" /> X-Large</label> <label for="large"><input type="checkbox" name="options" id="large" value="Large" /> Large</label> </p> <p> <label for="setStyle">Jersy Style: <input type="radio" id="homeStyle" name="setStyle" value="homeStyle" class="radio" /> Home <input type="radio" id="awayStyle" name="setStyle" value="awayStyle" class="radio" /> Away </label></p> <p> <label for="zip"> Zip: <input id="zip" name="zip" type="text" size="10" maxlength="5" class="isZip dealerList" /> </label></p> <p><input type="submit" value="Submit" /> <input type="reset" /></p> <p> </p> <p> </p> </form> Here is the JavaScript file attached: window.onload = initForms; function initForms() { for (var i=0; i< document.forms.length; i++) { document.forms[i].onsubmit = function() {return validForm();} } document.getElementById("medium").onclick = sizeSet; } function validForm() { var allGood = true; var allTags = document.getElementsByTagName("*"); for (var i=0; i<allTags.length; i++) { if (!validTag(allTags[i])) { allGood = false; } } return allGood; function validTag(thisTag) { var outClass = ""; var allClasses = thisTag.className.split(" "); for (var j=0; j<allClasses.length; j++) { outClass += validBasedOnClass(allClasses[j]) + " "; } thisTag.className = outClass; if (outClass.indexOf("invalid") > -1) { invalidLabel(thisTag.parentNode); thisTag.focus(); if (thisTag.nodeName == "INPUT") { thisTag.select(); } return false; } return true; function validBasedOnClass(thisClass) { var classBack = ""; switch(thisClass) { case "": case "invalid": break; case "reqd": if (allGood && thisTag.value == "") { classBack = "invalid "; } classBack += thisClass; break; case "radio": if (allGood && !radioPicked(thisTag.name)) { classBack = "invalid "; } classBack += thisClass; break; case "isNum": if (allGood && !isNum(thisTag.value)) { classBack = "invalid "; } classBack += thisClass; break; case "isZip": if (allGood && !isZip(thisTag.value)) { classBack = "invalid "; } classBack += thisClass; break; case "email": if (allGood && !validEmail(thisTag.value)) { classBack = "invalid "; } classBack += thisClass; break; default: if (allGood && !crossCheck(thisTag,thisClass)) { classBack = "invalid "; } classBack += thisClass; } return classBack; } function crossCheck(inTag,otherFieldID) { if (!document.getElementById(otherFieldID)) { return false; } return (inTag.value != "" || document.getElementById(otherFieldID).value != ""); } function radioPicked(radioName) { var radioSet = ""; for (var k=0; k<document.forms.length; k++) { if (!radioSet) { radioSet = document.forms[k][radioName]; } } if (!radioSet) { return false; } for (k=0; k<radioSet.length; k++) { if (radioSet[k].checked) { return true; } } return false; } function isNum(passedVal) { if (passedVal == "") { return false; } for (var k=0; k<passedVal.length; k++) { if (passedVal.charAt(k) < "0") { return false; } if (passedVal.charAt(k) > "9") { return false; } } return true; } function isZip(inZip) { if (inZip == "") { return true; } return (isNum(inZip)); } function validEmail(email) { var invalidChars = " /:,;"; if (email == "") { return false; } for (var k=0; k<invalidChars.length; k++) { var badChar = invalidChars.charAt(k); if (email.indexOf(badChar) > -1) { return false; } } var atPos = email.indexOf("@",1); if (atPos == -1) { return false; } if (email.indexOf("@",atPos+1) != -1) { return false; } var periodPos = email.indexOf(".",atPos); if (periodPos == -1) { return false; } if (periodPos+3 > email.length) { return false; } return true; } function invalidLabel(parentTag) { if (parentTag.nodeName == "LABEL") { parentTag.className += " invalid"; } } } } function sizeSet() { if (this.checked) { document.getElementById("homeStyle").checked = true; } } Thank you very much in advance for any and all help. I am a noob with JavaScript. I didn't know where else to turn for help. Thanks in advance, guys. The URL of the page I'm working on can be found he http://graph-art.matc.edu/romanot/vi...inal/order.php i have been working on Javascript and HTML for long time but never had such kind of a problem. A very simple code isnt getting executed. Please help me out with what i am missing : Here is the HTML code with javascript(a very simple webpage to say hello) : Code: <html> <head> <script type = "Javascript"> function say_hi() { window.alert("Said hiii.."); } </script> </head> <body> ahgdahsgdhagshd <input type = "checkbox" onclick= say_hi()/>click the check box sdfsdf </body> </html> Problem is that say_hi() isnt getting called. I have tried : Code: onclick= "say_hi();" also.. but still its not getting called when i am clicking the checkbox which it should!!! Yes but if i am writing : Code: onclick= "window.alert("Hi");" then its getting executed!!!. Whats going on here in my code. Thanks in advance Hey. I'm kind stuck here. I can't see what's wrong with this small set of code? Is there anything wrong? I'm trying to follow a tutorial at themeforest.net, but i'm getting both confused and frustrated as it doesn't do anything at all! Code: <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script src="jquery-1.4.1.min.js" type="text/javascript"></script> <style type="text/css"> #box { height: 300px; width: 300px; background: #2367AB; } </style> <script type="text/javascript"> $(document).ready(function() { $('a').click(function() { $('box').fadeOut(1000); }); }); </script> </head> <body> <div id="box"></div> <a href="#">Click me!</a> </body> </html> |