JavaScript - Javascript Function Calculation Issue
Hello,
I am trying to make a page with a target heart rate calculator that displays the heart rate in a text box. This code displays on a new page instead of in the box even though I put an input box, plus it doesn't display the correct value. I think the problem is in the function itself: Code: <script> function calcHeartRate() { var age = "" var heartRate = 220 - age var minRate = heartRate * .5 var maxRate = heartRate * .85 rate = document.write(heartRate) document.myForm.yourRate.value = rate } At any rate, here is the form also: Code: <form name = "myForm"> Age:</br> <input type = "text" name = "age" /><br/><br/> <input type = "button" value = "Calculate Your Maximum Heart Rate:" onclick= "calcHeartRate()"/> <br/><br/> Max Heart Rate:<br/> <input type = "text" name = "yourRate" /><br/><br/> </form> I'm sure this is jacked up code since I have definitely been struggling. If you want me to post my entire code, I will, but it is my understanding that it is against the guidelines. Posting a working code is definitely not necessary. Please give me an idea as to what is wrong and I will go from there. I do not want the actual answer. I kind of think the problem is with my age variable but I am not sure what it is. Thanks! Similar TutorialsThe problem that I am facing is my total amount comes out to $102.46 through my calculations on the page. But when it is moved over to PayPal, the value becomes $102.44. I have many more amount that are also either up .2 cents or down .2 cents. I managed to track this down as a rounding issue. Anytime I do the math, it rounds the amount off and gives the total. But since quantity is involved which is done through PayPal, I had to divide my total by the quantity to bring it back to its original amount thus allowing PayPal to multiply the amount by the quantity. I've pulled my hair out on this one. Ay help would be appreciated. Thank you Code: <html> <head> <title>TESTING</title> <script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationCheckbox.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css"> <link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css"> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css"> </head> <td width="95%" align="center" class="TextoImageSpace"><table border="0" cellpadding="0" cellspacing="0" class="TextoImageSpace_center"> <tr> <td align="center"><h2>Pricing</h2> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="price" id="price"> <p>Select amount please.</p> <p> <input type="hidden" name="cmd" value="_xclick" /> State: <br /> <span id="spryselect1"> <!-- selects the state // onclick changes the variables specified values --> <select name="combo0" id="combo_0" onclick="roundNumber(amount2.value, 2);roundNumberTax(tax.value, 2);roundNumberProduct(product.value, 2);roundNumberShipping(shipping.value, 2);roundNumberAmount(amount2.value, 2)" style="width:200px;"> <option selected="selected"> </option> <option value="70">Arizona</option> </select> <span class="selectRequiredMsg"></span></span><br /> Quantity: <br /> <span id="spryselect2"> <!-- selects the quantity // onclick changes the variables specified values --> <select name="combo1" id="combo_1" onclick="roundNumber(amount2.value, 2);roundNumberTax(tax.value, 2);roundNumberProduct(product.value, 2);roundNumberShipping(shipping.value, 2);roundNumberAmount(amount2.value, 2)" style="width:200px;"> <option selected="selected"> </option> <option value="4">4 - $20.95</option> </select> <span class="selectRequiredMsg"></span></span><br /> Product: <br /> <span id="sprytextfield11"> <label> <input type="text" name="product" id="txt_product" disabled="disabled" value="" style="width:200px;" /> </label> </span><br /> Shipping: <br /> <span id="sprytextfield9"> <label> <input type="text" name="shipping" id="txt_shipping" disabled="disabled" value="" style="width:200px;" /> </label> </span><br /> Taxes: <br /> <span id="sprytextfield10"> <label> <input type="text" name="tax" id="txt_tax" disabled="disabled" value="" style="width:200px;" /> </label> </span><br /> Total: <span id="sprytextfield8"> <input type="hidden" name="amount" id="txt_price" value="" style="width:200px;" /> </span> <input type="hidden" name="amount3" id="txt_price3" value="" style="width:200px;" /> <br /> <span id="sprytextfield7"> <input type="text" name="amount2" id="txt_price2" disabled="disabled" value="" style="width:200px;" /> </span></p> <hr width="100%" /> <p>Please fill in details.</p> <p> <input type="hidden" name="item_name" value="TEST ITEM" /> <input type="hidden" name="button_subtype" value="products" /> <input type="hidden" name="rm" value="1" /> <input type="hidden" name="return" value="http://www.example.com/" /> <input type="hidden" name="cancel_return" value="http://www.example.com/" /> <input type="hidden" name="currency_code" value="USD" /> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted" /> <input type="hidden" name="address_override" value="1" /> <input type="hidden" name="shipping" value="0" /> <input type="hidden" name="business" value="wayne@lifelikemedia.ca" /> <input type="hidden" name="quantity" id="quantity" value="1" /> <input type="hidden" name="state" id="state" value="" /> First Name: <br /> <span id="sprytextfield1"> <input type="text" name="first_name" value="TEST" style="width:200px;" /> <span class="textfieldRequiredMsg"></span></span><br /> Last Name: <br /> <span id="sprytextfield2"> <input type="text" name="last_name" value="TEST" style="width:200px;" /> </span> <br /> Address: <br /> <span id="sprytextfield3"> <input type="text" name="address1" value="1234 TEST STREET" style="width:200px;" /> <span class="textfieldRequiredMsg"></span></span><br /> City: <br /> <span id="sprytextfield4"> <input name="city" type="text" value="Scottsdale" style="width:200px;" /> <span class="textfieldRequiredMsg"></span></span><br /> ZIP Code: <br /> <span id="sprytextfield5"> <input type="text" name="zip" value="85260" style="width:200px;" /> </span><br /> Country: <br /> <span id="sprytextfield6"> <input name="country" type="text" disabled="disabled" value="US" style="width:200px;" /> </span><br /> <br /> <span id="sprycheckbox1"> <label> <input type="checkbox" name="replacePolicy" id="replacePolicy" /> </label> <span class="checkboxRequiredMsg">Please read policy.</span></span> <a href="#" class="style10" onClick="window.open('replace.html','popup','width=400,height=300,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=0'); return false">Please read policy.</a><br /> <br /> <input type="image" name="submit" border="0" src="http://www.thinkanddone.com/finance/buynow.jpg" alt="PayPal - The safer, easier way to pay online" /> </p> </form></td> </tr> </table> <script type="text/javascript"> var shipping = document.getElementById("txt_shipping").value; var tax = document.getElementById("txt_tax").value; var product = document.getElementById("txt_product").value; // rounds total amount off function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places var v1 = document.getElementById("combo_1").value, v2 = document.getElementById("combo_0").value; var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); var newnumber2 = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.amount2.value = newnumber.toFixed(2); // Output the result to the form field document.price.amount.value = (newnumber2 / v1).toFixed(2); } // rounds tax off function roundNumberTax(rnum, rlength) { // Arguments: number to round, number of decimal places var taxnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.tax.value = taxnumber.toFixed(2); // Output the result to the form field } // rounds product off function roundNumberProduct(rnum, rlength) { // Arguments: number to round, number of decimal places var productnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.product.value = productnumber.toFixed(2); // Output the result to the form field } // rounds shipping off function roundNumberShipping(rnum, rlength) { // Arguments: number to round, number of decimal places var shippingnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.shipping.value = shippingnumber.toFixed(2); // Output the result to the form field } // rounds paypal amount off function roundNumberAmount(rnum, rlength) { // Arguments: number to round, number of decimal places var amountnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.amount2.value = amountnumber.toFixed(2); // Output the result to the form field } window.onload = function() { var dropChange = function() { // Declaring variables var v1 = document.getElementById("combo_1").value, v2 = document.getElementById("combo_0").value; var amount3 = document.getElementById("txt_price3").value, amount = document.getElementById("txt_price").value; document.getElementById("txt_price3").value = (amount); document.getElementById("quantity").value = (v1); if (v2 == 70) { document.getElementById("state").value = ("AZ"); } <!-- when state is selected, these calculations are done --> if (v2 == 70) { if (v1 == 4) { document.getElementById("txt_price2").value = v1 * 20.95; document.getElementById("txt_product").value = document.getElementById("txt_price2").value; document.getElementById("txt_price2").value = document.getElementById("txt_product").value * 0.0795; document.getElementById("txt_tax").value = document.getElementById("txt_price2").value; document.getElementById("txt_price2").value = 12; document.getElementById("txt_shipping").value = document.getElementById("txt_price2").value; document.getElementById("txt_price2").value = v1 * 20.95 * 1.0795 + 12.00; } } }; document.getElementById("combo_0").onchange = dropChange; document.getElementById("combo_1").onchange = dropChange; }; </script> <script type="text/javascript"> <!-- var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {validateOn:["change"]}); var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {validateOn:["change"]}); var sprycheckbox1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1", {validateOn:["change"]}); var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "none"); var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "zip_code", {validateOn:["change"]}); var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "none"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "none"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none"); var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none"); var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7", "none", {validateOn:["change"]}); var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8", "currency", {validateOn:["change"]}); var sprytextfield10 = new Spry.Widget.ValidationTextField("sprytextfield10"); var sprytextfield9 = new Spry.Widget.ValidationTextField("sprytextfield9"); var sprytextfield11 = new Spry.Widget.ValidationTextField("sprytextfield11"); //--> </script> </body> </html> Hi everyone, I am new to Javascript and took a class or 2 in college, but need some help. I need to make a calculation for a webpage that will do the following: Client will insert AWG (wire ) Size, then it will derive the correct Circular Mils that the AWG is equal to from an Access Database ( I assume this is the way to set that up or if I can in Javascript itself, thats fine as well ), then Multiply it by the Number of Strands that the Client will also insert. I had this all set up in Visual Basic and working great, and my boss said he does not want it in a pop up box but prefers it on the website itself hence me reverting to Javascript for this. To visualize it Image 2 boxes with AWG and STRANDS that the client will put in, then another box with TOTAL CMA where the answer will pop up after it has multipled by the AWG individual CMA and number of Strands. I have the general idea to set it up, just do not know how to get the Database in there and Code it properly or whatever. I would appreciate any assistance I can get :-) Thanks everyone. What code must I use if I want to create an order form on my website where patrons can order and/or request a product and/or services from the price list, the order form should calculate the total amount of the products/services requested, the VAT of 15% and add that to the order amount, Please help?
Hello, javascript seems to return the calculate the follwoing: (1 / 0.88) * 4.4 = 5.000000000000001 Excel evaluates the same sum to be 5 even to 20 decimal points. My calculator does the same. Having the 1 on the end throws off some of my calculations. Why is javascript evaluating like this?? Many thanks All, Below find my JS which is supposed to do the following: Take user supplied numerical values from 7 fields, perform the calculation function that's in the code and place it into the Total box / field. Needless to say ...or I wouldn't be here...it doesn't work. I thought maybe the problem was in the function, but I'm not sure Thanks to all who can help! NewbieScott ================================ <html> <head> <title>Test Prototype</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style type="text/css"> * { margin:0; padding:0; } body { background:#fff; } p { margin:2em; } </style> <script type="text/javascript"> function calc(D1,D2,D3,D4,D5,D6,D7){ return (((D1*2.036+D3)/(273+D5))-((D2*2.036+D4)/(273+D6)))*238*(3050/D7); var D1=parseInt(D1.value); var D2=parseInt(D2.value); var D3=parseInt(D3.value); var D4=parseInt(D4.value); var D5=parseInt(D5.value); var D6=parseInt(D6.value); var D7=parseInt(D7.value); if (isNaN(D1)) {D1=0;} if (isNaN(D2)) {D2=0;} if (isNaN(D3)) {D3=0;} if (isNaN(D4)) {D4=0;} if (isNaN(D5)) {D5=0;} if (isNaN(D6)) {D6=0;} if (isNaN(D7)) {D7=0;} document.getElementById('total').value = D1+D2+D3+D4+D5+D6+D7; } window.onload=function() { var D1=document.getElementById('D1'); var D2=document.getElementById('D2'); var D3=document.getElementById('D3'); var D4=document.getElementById('D4'); var D5=document.getElementById('D5'); var D6=document.getElementById('D6'); var D7=document.getElementById('D7'); D1.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D2.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D3.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D4.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D5.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D6.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D7.onkeyup=function() {calc(D1,D2,D3,D4,D5,D6,D7); } </script> </head> <body> <form action="#"> <p><label> Number 1: <input id="D1"></label> <p><label> Number 2: <input id="D2"></label> <p><label> Number 3: <input id="D3"></label> <p><label> Number 4: <input id="D4"></label> <p><label> Number 5: <input id="D5"></label> <p><label> Number 6: <input id="D6"></label> <p><label> Number 7: <input id="D7"></label> <p>Total = <input id="total"></p> </p> </body> </html> Hi, I'm trying to get my head around JS, but not too successfully yet. My objective is probably simple (but not to me ): to have a form where visitors enter 12 separate digits (ideally in minutes & hours, but am happy to use decimals), and the average of these (to two decimal points) is returned as document.write is it? - along with other text, to make a complete & coherent sentence, including the average of the 12 numbers. Does anyone have any code convenient that could do this? Thanks, LJ I've designed a snippet of javascript to receive numbers, add them together, and then display the total. What i'd like to do now is display the amount of numbers added together "count", and then average them all together. Problem is, the count just won't display, so i'm uncertain if I have a logic error in my code or just an html issue? I'd really appreciate the help! Code: <html> <head> <script type="text/javascript"> var count = 0; var total = 0; var number = 0; function AverageNumbers(form) { number = document.getElementById('num1').value; count++; total = parseInt(number) + parseInt(total); average = parseInt(number) + parseInt(count) if (number!=null && number!="") { document.getElementById('total').innerHTML = total; document.getElementById('count').innerHTML = count; } return count; return total; } </script> </head> <body> <form> <INPUT TYPE="number" NAME="inputbox" ID="num1"> <INPUT TYPE="button" NAME="button" Value="Click" onClick="AverageNumbers(this.form)"> </form> <div id="total"><div> <br> </br> <div id="count"><div> </body> </html> Hi there! I hope someone can help me figure out the last little bit of this project. I'm building a form that is calulated based on the options selected with a javascript form. This is my first attempt at something like this so I'm a bit lost at the final update. First to be sure I'm on spot here is the javascript I'm using to update the form - Code: <script> function BDWcalc () { var listeners = document.getElementById('listeners').value; var bitrate = document.getElementById('bitrate').value; var hours = document.getElementById('hours').value; var days = document.getElementById('days').value; var total = document.getElementById('BDWTotal'); var sum = days*hours*3600*bitrate/8*listeners/1024/1024; total.value = sum.toFixed(2)+" GB"; } </script> I'm calling the script in the header of the site with the following line of code Code: <script type="text/javascript" language="JavaScript" src='javascript/BDWcalc.js'></script> Now here is the form where I get stuck. It the last field which is to be updated when the option values are changed. For my purposes here, I've merely created a correct value as a default based on the items selected, but it is not actually being calculated by the script. I need the correct syntax there to get this all to work. Sure hope someone can help - Form Code: <table width="530" border="0" cellspacing="0" cellpadding="5"> <tr> <th scope="col">Listeners</th> <th scope="col">Bitrate(quality)</th> <th scope="col">Hours per day </th> <th scope="col">Days per month </th> <th scope="col">Total per month </th> <th scope="col">Action</th> </tr> <tr> <th scope="col"><span class="cell" style="width: 75px;"> <input name="text" type="text" id="listeners" style="margin: 4px 2px 0pt; width: 65px;" onchange="BDWcalc();" value="10" size="20" /> </span></th> <th scope="col"><span class="cell_v"> <select name="select2" class="BDWbox" id="select" onchange="BDWcalc();"> <option value="24">24 kbps</option> <option value="32">32 kbps</option> <option value="48">48 kbps</option> <option value="56">56 kbps</option> <option value="64" selected="selected">64 kbps</option> <option value="80">80 kbps</option> <option value="96">96 kbps</option> <option value="112">112 kbps</option> <option value="128">128 kbps</option> <option value="160">160 kbps</option> <option value="192">192 kbps</option> <option value="224">224 kbps</option> <option value="256">256 kbps</option> <option value="320">320 kbps</option> <option value="512">512 kbps</option> <option value="768">768 kbps</option> <option value="1536">1.5 mbps</option> </select> </span></th> <th scope="col"><span class="cell_v"> <select name="select3" class="BDWbox" id="select2" onchange="BDWcalc();"> <option value="1">1 hour</option> <option value="2">2 hours</option> <option value="3">3 hours</option> <option value="4">4 hours</option> <option value="5">5 hours</option> <option value="6">6 hours</option> <option value="7">7 hours</option> <option value="8">8 hours</option> <option value="9">9 hours</option> <option value="10" selected="selected">10 hours</option> <option value="11">11 hours</option> <option value="12">12 hours</option> <option value="13">13 hours</option> <option value="14">14 hours</option> <option value="15">15 hours</option> <option value="16">16 hours</option> <option value="17">17 hours</option> <option value="18">18 hours</option> <option value="19">19 hours</option> <option value="20">20 hours</option> <option value="21">21 hours</option> <option value="22">22 hours</option> <option value="23">23 hours</option> <option value="24">24 hours</option> </select> </span></th> <th scope="col"><span class="cell_v"> <select name="select4" class="BDWbox" id="select3" onchange="BDWcalc();"> <option value="1">1 day</option> <option value="2">2 days</option> <option value="3">3 days</option> <option value="4">4 days</option> <option value="5">5 days</option> <option value="6">6 days</option> <option value="7">7 days</option> <option value="8">8 days</option> <option value="9">9 days</option> <option value="10">10 days</option> <option value="11">11 days</option> <option value="12">12 days</option> <option value="13">13 days</option> <option value="14">14 days</option> <option value="15" selected="selected">15 days</option> <option value="16">16 days</option> <option value="17">17 days</option> <option value="18">18 days</option> <option value="19">19 days</option> <option value="20">20 days</option> <option value="21">21 days</option> <option value="22">22 days</option> <option value="23">23 days</option> <option value="24">24 days</option> <option value="25">25 days</option> <option value="26">26 days</option> <option value="27">27 days</option> <option value="28">28 days</option> <option value="29">29 days</option> <option value="30">30 days</option> </select> </span></th> <th scope="col"><span class="cell_v" style="width: 160px;"> <input name="text2" type="text" id="text2" style="margin: 4px 2px 0pt; width: 90px;" value="41.19 GB" size="20" /> </span></th> <th scope="col"><a href='javascript:BDWcalc();'>Update</a></th> </tr> </table> The form can be view here Thank you in advance for any help offered. I've search and found things that are similiar, but none that are exactly what I need here. Ruth I have a javascript that should convert any date into a number between 1 and 260. Based on the outcome of that calculation, a viewer is directed to a specific web page. How can I verify the calculation? How can I see what number javascript is arriving at so I can backtrack to the error? It is not serving up the correct page. I have compared the results to a calculator on another website that uses a different script to calculate the same result -- that's why I am saying the end results are not correct. On the other website, scroll down to where you enter a date. It returns a name just above the date (example: July 25, 1970 returns Electric Star). The script I included above returns Yellow Sun. July 25, 1970 should = 68. Code: function calculate() { if(!isValidDate()) return; var result = 0; var cuttingAge = 260; var yearBox = document.getElementById("year"); var year = yearBox.value; var month = document.getElementById("month").value; var day = document.getElementById("day").value; //Rule # 1 if(month==1 || month==2){ var selectedYearIndex; for(var i=0; i<yearBox.options.length; i++){ if(yearBox.options[i].selected){ selectedYearIndex = i; break; } } year = yearBox.options[selectedYearIndex-1].value; } //Rule # 2 var monthLength = new Array(); monthLength[0]=0; monthLength[1]=31; monthLength[2]=29; monthLength[3]=31; monthLength[4]=30; monthLength[5]=31; monthLength[6]=30; monthLength[7]=31; monthLength[8]=31; monthLength[9]=30; monthLength[10]=31; monthLength[11]=30; monthLength[12]=31; monthLength[13]=31; monthLength[14]=29; var dayPassed = 0; var tempMonth = month; if(month<3) //If its january or february tempMonth = parseInt(tempMonth) +12; //Add previous year's days for(var i=3; i<tempMonth; i++){ dayPassed += monthLength[i]; } dayPassed += parseInt(day) -1; dayPassed = dayPassed%cuttingAge; //Rule # 3 result = parseInt(year) + parseInt(dayPassed); //Rule # 4 if(result > cuttingAge) result -= cuttingAge; //Rule # 5 var pendant = new Array(); var abc = new Array(); pendant[0] = { name:"imix", values:new Array(1, 21, 41, 61, 81, 101, 121, 141, 161, 181, 201, 221, 241) }; pendant[1] = { name:"ik", values:new Array(2, 22, 42, 62, 82, 102, 122, 142, 162, 182, 202, 222, 242) }; pendant[2] = { name:"akbal", values:new Array(3, 23, 43, 63, 83, 103, 123, 143, 163, 183, 203, 223, 243) }; pendant[3] = { name:"kan", values:new Array(4, 24, 44, 64, 84, 104, 124, 144, 164, 184, 204, 224, 244) }; pendant[4] = { name:"chicchan", values:new Array(5, 25, 45, 65, 85, 105, 125, 145, 165, 185, 205, 225, 245) }; pendant[5] = { name:"cimi", values:new Array(6, 26, 46, 66, 86, 106, 126, 146, 166, 186, 206, 226, 246) }; pendant[6] = { name:"manik", values:new Array(7, 27, 47, 67, 87, 107, 127, 147, 167, 187, 207, 227, 247) }; pendant[7] = { name:"lamat", values:new Array(8, 28, 48, 68, 88, 108, 128, 148, 168, 188, 208, 228, 248) }; pendant[8] = { name:"muluk", values:new Array(9, 29, 49, 69, 89, 109, 129, 149, 169, 189, 209, 229, 249) }; pendant[9] = { name:"oc", values:new Array(10, 30, 50, 70, 90, 110, 130, 150, 170, 190, 210, 230, 250) }; pendant[10] = { name:"chuen", values:new Array(11, 31, 51, 71, 91, 111, 131, 151, 171, 191, 211, 231, 251) }; pendant[11] = { name:"eb", values:new Array(12, 32, 52, 72, 92, 112, 132, 152, 172, 192, 212, 232, 252) }; pendant[12] = { name:"ben", values:new Array(13, 33, 53, 73, 93, 113, 133, 153, 173, 193, 213, 233, 253) }; pendant[13] = { name:"ix", values:new Array(14, 34, 54, 74, 94, 114, 134, 154, 174, 194, 214, 234, 254) }; pendant[14] = { name:"men", values:new Array(15, 35, 55, 75, 95, 115, 135, 155, 175, 195, 215, 235, 255) }; pendant[15] = { name:"cib", values:new Array(16, 36, 56, 76, 96, 116, 136, 156, 176, 196, 216, 236, 256) }; pendant[16] = { name:"caban", values:new Array(17, 37, 57, 77, 97, 117, 137, 157, 177, 197, 217, 237, 257) }; pendant[17] = { name:"etznab", values:new Array(18, 38, 58, 78, 98, 118, 138, 158, 178, 198, 218, 238, 258) }; pendant[18] = { name:"cauac", values:new Array(19, 39, 59, 79, 99, 119, 139, 159, 179, 199, 219, 239, 259) }; pendant[19] = { name:"ahau", values:new Array(20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260) }; var redirecctPages = new Array(); redirecctPages["chuen"] = "http://store.mayankin.com/blue-monkey/"; redirecctPages["eb"] = "http://store.mayankin.com/yellow-human/"; redirecctPages["ben"] = "http://store.mayankin.com/red-skywalker/"; redirecctPages["ix"] = "http://store.mayankin.com/white-wizard/"; redirecctPages["men"] = "http://store.mayankin.com/blue-eagle/"; redirecctPages["cib"] = "http://store.mayankin.com/yellow-warrior/"; redirecctPages["caban"] = "http://store.mayankin.com/red-earth/"; redirecctPages["etznab"] = "http://store.mayankin.com/white-mirror/"; redirecctPages["cauac"] = "http://store.mayankin.com/blue-storm/"; redirecctPages["ahau"] = "http://store.mayankin.com/yellow-sun/"; redirecctPages["imix"] = "http://store.mayankin.com/red-dragon/"; redirecctPages["ik"] = "http://store.mayankin.com/white-wind/"; redirecctPages["akbal"] = "http://store.mayankin.com/blue-night/"; redirecctPages["kan"] = "http://store.mayankin.com/yellow-seed/"; redirecctPages["chicchan"] = "http://store.mayankin.com/red-serpent/"; redirecctPages["cimi"] = "http://store.mayankin.com/white-world-bridger/"; redirecctPages["manik"] = "http://store.mayankin.com/blue-hand/"; redirecctPages["lamat"] = "http://store.mayankin.com/yellow-star/"; redirecctPages["muluk"] = "http://store.mayankin.com/red-moon/"; redirecctPages["oc"] = "http://store.mayankin.com/white-dog/"; var pendantName; for(var i =0; i<pendant.length; i++){ var found = false; for(var j=0; j<pendant[i].values.length; j++){ if(result == pendant[i].values[j]){ pendantName = pendant[i].name; found = true; break; } } if(found) break; } document.location = redirecctPages[pendantName]; } /** * Comment */ function isValidDate() { var year = document.getElementById("year").value; var month = document.getElementById("month").value; var day = document.getElementById("day").value; if(month==2 && day>29){ alert("Please select a valid date"); return false } if((month==4 || month==6 || month==9 || month==11) && day>30){ alert("Please select a valid date"); return false } return true; } Hi, I am facing a problem in passing replace() function as an argument in user defined java function, can any one help me how to resolve it? intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '\' to '\\' I am posting my javascript function he <a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\\/g,"\\\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a> function OpenDocPreview(url, docname) { alert('message from search base : ' + url + ' ' + docname); } thank you, I made a mouseover event of a caption on a picture, when I hover the opacity of the background color of the hover and the text goes down. What I want is that when I hover over the image which the caption is floating on, the onmouseover event gets activite. For an imaginary example: Code: function unhighlight(x) { x.style.backgroundColor="transparent" } Function ActivationFuction() { activate.function="unhighlight" } thanks How can I call a PHP Function inside a Javascript Function? This is what I have so far, but I don't think I'm doing it the right way. Any suggestions? PHP Code: <?php function phpQuery(){ $query = mysql_query("INSERT INTO mytable VALUES('','name','email')"); } ?> <script type="text/javascript"> function delayQueries() { timeoutID = window.setTimeout(doQueries, 2000); } function doQueries() { var runQuery = "<?php phpQuery(); ?>"; } </script> hey everyone: im using the following function: Code: function getByTag(tagName) { var i, results = [], nodes = document.getElementsByTagName(tagName); for (i = 0; i < nodes.length; i++) { results.push(nodes[i]); } return results; } however when im trying to do this getByTag("div").style.color = "red" nothing happens.any help? Good day everyone. I have a challenge with a function that works in Firefox, but not IE, Chrome or Safari. We've been building a site with a mix of Javascript and PHP using Google Maps. Another developer began the project and left a large mess which we're cleaning up. Even though it's under development, it can be viewed at www.recareas.com/demo The challenge we have is this . . . When the site home page, which is a large map, loads, it displays the US with state markers. The user will then select a state, for example, Colorado. The map then zooms in and displays markers for that state. Ultimately we won't be showing markers at the point until the visitor selects an activity from a menu. When the visitor clicks on a location marker, the google call out bubble pops up displaying a list of activities and a More Info button. This more info button when clicked opens a slide out dock on the right side of the screen displaying detailed data about the location selected. The problem we have is that this slide out dock only works in Firefox. It appears that in the other browsers the function that calls the PHP template that builds the right side dock doesn't even load. Can anyone help by giving us some pointers or direction? Here's the function were trying to call from the More Info bubble inside the google map: [code] function locInfo(loc_id) { $.get("includes/z_get_location_details.php", { loc_id: loc_id }, function(data){ $("#infoWindow_location").html(data); $("#r_menu").animate({ width: "500px"}, 200 ); $("#r_menu_left").hide(); $("#r_menu_right").show(); $("#infoWindow").show(); $.getScript("includes/z_get_interests.php?loc_id=" + loc_id); //document.directionsForm.goBtn.disabled=false; }, "html"); } [Icode] Thank you in advance for any help. Hi everyone, I am pretty new at javascript OOP. I have a javascript file that has plenty of javascript functions, variables, arrays, etc. I need to convert this into an object. Here is an example: Code: var myvar1 = ''; var myvar2 = new array(); var myvar3 = new array(); var myvar4; var myvar5 = 60; var myvar6 = ''; function myfunc1(){ myvar1 = 'hello'; return myvar1; } function myfunc2(somenum=0){ myvar5 = somenum; //calling myfunc1() from within this function. //do something in here } function myfunc3(){ //calling myfunc1() from within this function. for(i=0;i<somelength;i++){ myvar2 = myvar3[i]; (something to put into the array) } } 1. I need to create an object and put ALL the varibles (myvar1 - myvar5) in that object. 2. Then the first two functions "myfunc1 and myfunc2" inside the same object. 2. And the function myfunc3 needs to sit OUTSIDE my object as a regular javascript function. It calls on myfunc1 (which is inside the object) and also inserts data into myvar2 (which is classified inside the object) and myvar3 (which is classified inside the object as well). This is what i came up with, but it's not going well: Code: var myobj1 = function(){ this.myvar1 = ''; this.myvar2 = new array(); this.myvar3 = new array(); this.myvar4; this.myvar5 = 60; this.myvar6 = ''; var myfunc1 = function(){ this.myvar1 = 'hello'; return this.myvar1; } var myfunc2 = function(somenum=0;){ this.myvar5 = somenum; //calling this.myfunc1() from within this function. //do something in here } } function myfunc3(){ //calling mynewobj.myfunc1() from within this function. for(i=0;i<somelength;i++){ mynewobj.myvar2 = mynewobj.myvar3[i]; (something to put into the array) } } var mynewobj = myobj1; HELP.....!!!! i really want to get into object oriented world, so thanks in advance. I have created a function but it only half works. I can get the number of contributers to add up but not the total amount of dollars they contributed. I am not sure if my function is wrong or if I am just confused with what variable to output for the dollar amount total. Please assist. My Function: <script type="text/javascript"> function amountTotal() { total = 0; for (var i=0; i<=amount.length; i++) { total+=amount[i]; } return total; } </script> My output files: <div id=totals> <script type="text/javascript"> document.write("<table border=1' cellspacing=1'>"); document.write("<tr><th id=sumTitle colspan=2'>Summary</th></tr>"); document.write("<tr><th>Contributors</th>"); document.write("<td>"+[i]+"</td>"); document.write("</tr>"); document.write("<tr><th>Amount</th>"); document.write("<td>$ +[total]+</td></tr>"); document.write("</table>"); </script> Hi all, I'm just starting out with Javascript as a development language and this will probably be a relatively simple problem for someone to solve for me. I am trying to access a variable (this.bodyEl.innerHTML) from within a function but get an error message indicating that it is "undefined". I know that it is a valid variable because I call it elsewhere outside of the inner function itself. I'm sure this is just a scope issue, but I'd welcome any suggestions on how to solve it with an explanation of where I've gone wrong if you have the time. Here's the code: Code: displayFeed: function(responseData) { this.bodyEl.innerHTML = "xxxx"; // I can see this var responseDoc = Presto.Util.parseXml(responseData); var items = Ext.DomQuery.select("/rss/channel/item", responseDoc); items.each(function(item, bodyHTML) { var rssTitle = Ext.DomQuery.selectValue("/title", item); var rssDescription = Ext.DomQuery.selectValue("/description", item); var rssLink = Ext.DomQuery.selectValue("/link", item); // but this results in an undefined error this.bodyEl.innerHTML = '<a href="' + rssLink + '">' + rssTitle + '</a><br/>'; }); // end of items processing } This is a fragment of the code from my script. The first access of "this.bodyEl.innerHTML" works fine, but the second access in the items.each loop doesn't and I get an undefined variable error. Is this a scoping problem, and if so how is it best solved. Thanks in advance, Innes (NZ) Hi, I'm trying to call a Js function from a test.js located in a HTML file. I'm getting error message "Object has no method..." in Chrome. But no issues are seen in Firefox. Can any one please let me know how i can fix this. <html> <head> .... .... .... <div> <html> <head> <script src="test.js"></script> <script> function aFunc() { alert ("Inside aFunc"); } </script> </head> <body> </html> .... .... .... </div> </head> </html> test.js function bFunc () { aFunc (); } If I use function or Function to create a javascript function, does it make any difference ? Whats the difference between two and in which situation shall I use either ? Likewise whats the difference between event and Event objects of JavaScript ? Thanks |