JavaScript - Converter Problem
Hi all,
I have a problem about my converter.Why when I'm clicking on the keypad displayed in the form,it doesn't display the result.But when clicking on the keypad on the keyboard,it works?.Plz help me with this trouble.Here are my code. <-html-> <html> <head> <title>Currency Converter</title> <link rel="stylesheet" href="../css/cal.css" type="text/css" > <script type="text/javascript" src="../cal.js"></script> </head> <body> <h2>Currency Converter<h2> <table id="table1"> <form id="currconverter"> <tr> <td>Convert<br>from:</td> <td><input type="text" id="amount" value="" size="17" onChange="convertCurr()"></td> <td> <select id="from_select"> <option value="GBP" selected="selected">Pound Sterling</option> <option value="USD">US Dollar</option> <option value="MUR">Mauritian RS</option> <option value="EUR">Euro</option> <option value="JPY">Yen</option> </select> </td> </tr> <tr> <td>Convert<br>to:</td> <td><input type="text" id="result" value="" size="17" readonly="readonly" onchange="convertCurr();"></td> <td> <select id="to_select"> <option value="GBP">Pound Sterling</option> <option value="USD">US Dollar</option> <option value="MUR" selected="selected">Mauritian RS</option> <option value="EUR">Euro</option> <option value="JPY">Yen</option> </select> </td> </tr> </form> </table> <br> <table cellpadding="0" cellspacing="5" border="1" align="center" bgcolor="AABBCC"> <form name="cal"> <tr> <td><input type="button" value="7" onClick="currconverter.amount.value += '7'"></td> <td><input type="button" value="8" onClick="currconverter.amount.value += '8'"></td> <td><input type="button" value="9" onClick="currconverter.amount.value += '9'"></td> </tr> <tr> <td><input type="button" value="4" onClick="currconverter.amount.value += '4'"></td> <td><input type="button" value="5" onClick="currconverter.amount.value += '5'"></td> <td><input type="button" value="6" onClick="currconverter.amount.value += '6'"></td> </tr> <tr> <td><input type="button" value="1" onClick="currconverter.amount.value += '1'"></td> <td><input type="button" value="2" onClick="currconverter.amount.value += '2'"></td> <td><input type="button" value="3" onClick="currconverter.amount.value += '3'"></td> </tr> <tr> <td><input type="button" value="0" onClick="currconverter.amount.value += '0'"></td> <td><input type="button" value="." onClick="currconverter.amount.value += '.'"></td> <td><input type="reset" value="C" OnClick="currconverter.amount.value = ''"></td> </tr> </form> </table> </body> </html> <-javascript-> function convertCurr() { var amount = parseFloat(document.getElementById("amount").value); var form = document.getElementById("currConverter"); var fromSelect = document.getElementById("from_select"); var toSelect = document.getElementById("to_select"); var result= document.getElementById("result"); var currencyTo = []; switch (fromSelect.value) { case "GBP": currencyTo = [1, 1.61, 46.91, 1.23, 128.89]; break; case "USD": currencyTo = [1.62, 1, 28.90, 0.76, 79.84]; break; case "MUR": currencyTo = [1.02, 0.03, 1, 0.03, 0.00]; break; case "EUR": currencyTo = [0.81, 1.31, 38.01, 1, 104.47]; break; case "JPY": currencyTo = [0.01, 1.25, 0.00, 0.96, 1]; break; default: alert("It broke."); } result.value = (amount * currencyTo[toSelect.selectedIndex]).toFixed(2); } Similar TutorialsHello, I've been reading my JS book, have done a 'Degrees Converter' which converts fahrenheit into centigrade. There is a prompt box which automatically loads when the website is loaded. I am pressuming this is because I have my script in the body. I have a question if anybody could possibly help me out. How do I get my script as a link? To explain a little better, I wanted to put the words 'Degrees Converter' onto my page(as a link), so that when people click the link, it loads up the prompt box. I'm very new to JavaScript, so if anyone could help me out it would be a great help. Thank you very much. Hi I have the following currency converter code which works fine, but I need to make it possible for someone else to edit the euro price using a visual editor such as contribute. 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 language='javascript'> exchRate = 1.13; function getUKP(price) { document.write('(£' + Math.round(price / exchRate) + ')'); } </script> </head> <body> <strong>€526</strong> <script type="text/javascript">getUKP('526');</script><br /><br /> <strong>€1999</strong> <script type="text/javascript">getUKP('1999');</script> </body> </html> This code requires someone to change the figure in the javascript as well as the html. I guess I need to somehow automatically pick up the numeric characters only from the html which appear on the same line of code... or perhaps there's an easier way.? Any help would be much appreciated. Thanks Hi all -- I realize this is probably pretty simple, but it's been a while since I did any Javascripting, and things have changed a great deal. My apologies if I sound a bit clueless. I need to create a conversion tool. On one side of the tool are 4 form boxes. On the other, just text (not in form boxes). Under the covers, I have formulas for converting the numbers -- mostly basic math functions. So, the user types in numbers, clicks convert and the text changes. For some reason, I'm having a hard time getting this to go. How can I get the results of these calculations to show up as text within a DIV tag and not inside a form element? There are lots of examples of getting these calculations to appear within form boxes, but not within DIVs. Any examples would be greatly appreciated. This page is already using the Dojo toolkit for some other functionality, is this something I could leverage here to build my Javascript? Thanks in advance for your patience. Hello, I am having trouble with a javascript length converter that I got from http://www.javascriptkit.com/script/...onverter.shtml It is working fine in dreamweaver, but when it goes live on my site, the calculations do nothing. I can see everything in the drop down menus, but when i click the "to" button, nothing happens. I got the following errors from chrome when activating any of the calculation functions. I'm wondering if anyone here can help me decipher these 1. Uncaught TypeError: Cannot read property 'from_unit' of undefined 1. convert_unitDefault.aspx:459 2. (anonymous function)Default.aspx:482 3. onchangeDefault.aspx:483 1. Default.aspx:459Uncaught TypeError: Cannot read property 'from_unit' of undefined 1. convert_unitDefault.aspx:459 2. (anonymous function)Default.aspx:496 3. onchangeDefault.aspx:497 1. Default.aspx:459Uncaught TypeError: Cannot read property 'from_unit' of undefined 1. convert_unitDefault.aspx:459 2. (anonymous function)Default.aspx:516 3. onclickDefault.aspx:517 Hello all. I'm so glad i found this forum!!! This looks like a great coding community. This will be my First Post. I was wondering if you guys can help me with my weight converter. I cant seem to make it work properly on my site. here is the code im using: <p class="about">Convert weight measurements between U.S./Imperial and SI (Metric) units<br /> Type your value in a box, click the <input onclick="alert('Not this button!')" type="button" name="test_bt" value="Go!" /> and all unit conversions in the same category will be calculated.</p> <form action=""> <table width="500" border="1" cellspacing="0" cellpadding="4"> <tbody> <tr bgcolor="#0066ff"><th class="headings" colspan="3" bgcolor="#1765BB">SI (Metric)</th></tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">Tonne</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="mTon" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(mTon.value)) compute(this.form,mTon.name,weight_data)" type="button" name="mTon_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">Kilogram (kg)</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="mKilogram" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(mKilogram.value)) compute(this.form,mKilogram.name,weight_data)" type="button" name="mKilogram_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">Gram (g)</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="mGram" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(mGram.value)) compute(this.form,mGram.name,weight_data)" type="button" name="mGram_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">Milligram (mg)</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="mMilligram" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(mMilligram.value)) compute(this.form,mMilligram.name,weight_data)" type="button" name="mMilligram_bt" value="Go!" /></td> </tr> <tr><th class="headings" colspan="3" bgcolor="#103e78"> </th></tr> <tr bgcolor="#0066ff"><th class="headings" colspan="3" bgcolor="#1765BB">Troy weight</th></tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">Pound (lb t)</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="troyPound" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(troyPound.value)) compute(this.form,troyPound.name,weight_data)" type="button" name="troyPound_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">Ounce (oz t)</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="troyOunce" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(troyOunce.value)) compute(this.form,troyOunce.name,weight_data)" type="button" name="troyOunce_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">PennyWeight (dwt)</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="troyDWT" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(troyDWT.value)) compute(this.form,troyDWT.name,weight_data)" type="button" name="troyDWT_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" width="288">Grain<br /> Same as Avoirdupois grain</td> <td class="headings" align="right" bgcolor="#103e78" width="130"><input type="text" name="troyGrain" size="15" /></td> <td class="headings" bgcolor="#103e78" width="57"><input onclick="if (checkNum(troyGrain.value)) compute(this.form,troyGrain.name,weight_data)" type="button" name="troyGrain_bt" value="Go!" /></td> </tr> <tr bgcolor="#6699ff"> <td class="headings" colspan="3" bgcolor="#103e78"> </td> </tr> <tr bgcolor="#0066ff"><th class="headings" colspan="3" bgcolor="#1765BB">Avoirdupois weight</th></tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">British ("long") ton</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="briTon" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(briTon.value)) compute(this.form,briTon.name,weight_data)" type="button" name="briTon_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">US ("short") ton</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="usTon" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(usTon.value)) compute(this.form,usTon.name,weight_data)" type="button" name="usTon_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78" height="42">British ("long") hundredweight (cwt)</td> <td class="headings" align="right" bgcolor="#103e78" height="42"><input type="text" name="briCWT" size="15" /></td> <td class="headings" bgcolor="#103e78" height="42"><input onclick="if (checkNum(briCWT.value)) compute(this.form,briCWT.name,weight_data)" type="button" name="briCWT_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">US ("short") hundredweight (cwt)</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="usCWT" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(usCWT.value)) compute(this.form,usCWT.name,weight_data)" type="button" name="usCWT_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">Stone</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="briStone" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(briStone.value)) compute(this.form,briStone.name,weight_data)" type="button" name="briStone_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">Pound (lb)</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="avdpPound" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(avdpPound.value)) compute(this.form,avdpPound.name,weight_data)" type="button" name="avdpPound_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">Ounce (oz)</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="avdpOunce" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(avdpOunce.value)) compute(this.form,avdpOunce.name,weight_data)" type="button" name="avdpOunce_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">Dram (dr)</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="avdpDram" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(avdpDram.value)) compute(this.form,avdpDram.name,weight_data)" type="button" name="avdpDram_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" bgcolor="#103e78">Grain</td> <td class="headings" align="right" bgcolor="#103e78"><input type="text" name="avdpGrain" size="15" /></td> <td class="headings" bgcolor="#103e78"><input onclick="if (checkNum(avdpGrain.value)) compute(this.form,avdpGrain.name,weight_data)" type="button" name="avdpGrain_bt" value="Go!" /></td> </tr> <tr bgcolor="#0066ff"> <td class="headings" colspan="2" align="center" bgcolor="#103e78"><input onclick="resetAll(this.form)" type="button" name="res7" value="Clear all numbers" /></td> <td class="headings" bgcolor="#103e78"> </td> </tr> </tbody> </table> <p> </p> </form> <p> </p> and help will be greatly appreciated. Hey guys. I am in an introductory computer science class and I am having trouble writing JavaScript code for a currency converter. I can get it to where it spits out numbers, but its always the same numbers. I think there's something wrong in the calculations part of my code but I can't figure it out. I am posting it below, and any help would be greatly appreciated. Thank you. <html> <head> <title>CURRENCY CONVERTER</title> <script language="JavaScript"> function converting() { with (document.conversions) { if (unit[1].selected) { var result = eval(unit.value*0.974); convertedValue.value = result; } // end if if (unit[2].selected) { var result = eval(unit[2].value*0.492); convertedValue.value = result; } // end if if (unit[3].selected) { var result = eval(unit[3].value*0.706); convertedValue.value = result; } // end if } // end with } // end function converting </script> </head> <form name = "conversions"> <table border=6 bgcolor ="yellow"> <tr> <td><font color="red" size=6>Enter amount in U.S. $:</font></td> <td><input type="text" name="inUnit" size = 4></td> </tr> <tr> <td><font color="red" size=6>Select target unit:</font> <td><select name="unit"> <option value="Select Currency" selected>Choose one... <option value="1">Canadian Dollars <option value="2">British Pounds <option value="3">Euros </select> <td><input type="button" value="Convert" onclick="converting()"> </tr> <tr> <td><font color="green" size=6>Converted Value:</font> <td><input type="text" name="convertedValue" size = 4> <td><input type="reset" value="Reset"> </tr> </table> </form> </body> </html> Hi, I need to create a currency converter using a drop down menu. Firstly i needed to do a regular expressions check to make sure only numerics are entered and I got that. The one thing im pretty confused on is how to do the calculations in the actual function. Ive popped the code below, and if anyone could give me some hints on how to get the data from the drop down menu and calculate it properly that would be awesome. Thanks. -oh and i know all my coding is here but i think its relevent that you can view it all. Code: <html> <head> <style type ="text/css"> @import url(style.css); </style> <script type="text/javascript"> function convert() { var OK = true; var inDollar= document.getElementById('dollars').value; var regex= /^\d{1,}$/; if (!regex.test(inDollar)) { OK=false; alert('Australian Dollars must be entered as numeric with no decimal places'); } return OK; var rate= country.conversion.value; if (document.getElementByID('conversion').selectedIndex == 0) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' US Dollars'); } if (document.getElementByID('conversion').selectedIndex == 1) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' Euro'); } if (document.getElementByID('conversion').selectedIndex == 2) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' Yuan'); } if (document.getElementByID('conversion').selectedIndex == 3) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' Yen'); } } </script> </head> <body> <h1>Currency Page</h1> <form> Australian Dollars:<input type="text" name="dollars" id="dollars" /> <br /> Convert to: <select id='conversion' name='country'> <option value=".73">US Dollars</option> <option value=".62">Euro</option> <option value="5.8">Chinese Yuan</option> <option value="78.5">Japanese Yen</option> </select> <br /> <input type="button" value="Convert" onClick="convert()" /> </form> </body> </html> I can only seem to find really complicated ones online, nothing simple which i think this is. Thanks I am trying to make a unit converter with two dropdown boxes, two textfields and a button. I want to enter a number into the first textfield, select a unit option, then select another appropriate unit option based on the first selection, press the button and get the result in the second textfield. What would be the best approach for this. So far I have: <html> <head> <script type="text/javascript"> function convertUnit () { // convert pound to kilogram document.unitForm.toField.value = document.unitForm.fromField.value / 2.2; // convert kilogram to pound document.unitForm.toField.value = document.unitForm.fromField.value * 2.2; // convert inch to centimeter document.unitForm.toField.value = document.unitForm.fromField.value / 2.54; // convert centimeter to inch document.unitForm.toField.value = document.unitForm.fromField.value * 2.54; } </script> </head> <body style="background-color:lightgray"> <form action="" name="unitForm"> <input type="text" name="fromField" onfocus="this.form.fromField.value=''; style.background='lightyellow';" onblur="style.background='white';" /> <select name="fromList" > <option value="" selected="selected">Unit</option> <option id="fromPound" value="2.2">lb</option> <option id="fromKilogram" value="1.0">kg</option> <option id="fromInch" value="1.0">in</option> <option id="fromCentimeter" value="2.54">cm</option> </select> <input type="button" value="Convert" onclick="convertUnit()" /> <input type="text" name="toField" readonly="readonly" /> <select name="toList"> <option value="" selected="selected">Unit</option> <option name="toKilogram" id="toKilogram" value="1.0">kg</option> <option name="toPound" id="toPound" value="2.2">lb</option> <option name="toCentimeter" id="toCentimeter" value="2.54">cm</option> <option name="toInch" id="toInch" value="1.0">in</option> </select> <input type="reset" value="Reset" /> </form> </body> </html> I imagine this would be very simple for someone who knows javascript. I want to have three fields. First field is "posted speed limit", second field is "actual speed" and third field will be the output field. All the script needs to do it subtract the posted speed from the actual speed and add a ZERO to the end; which is the amount of the speeding ticket. The minimum fine is $100, however. So, 5 miles over the speed limit would be $100 (minimum value) 15 miles over the speed limit would be $150 (add a zero) 35 miles over the speed limit would be $350. etc. I know very little Javascript, if anyone could help me out with this, I'd appreciate it. Thanks, Sean Hi pals, I am really tired in this problem of event keyup. I given same in my keyup function like: $(document).ready(function () { alert("GGG"+parseInt(jQuery.browser.version)); //To display test value working $("#find_text").keyup(function(e) { if(e.which == 13) { alert('Enter key was pressed'); //enter Here alert("FFF"+parseInt(jQuery.browser.version)); //Here got Error } }); }); I got Error : jQuery is not defined alert("FFF"+parseInt(jQuery.browser.version)); I use keycode,which , but no help, It's Work nicely in Chrome Browser but not in FF. Please give a Solution reply ASAP, I am really Tired.The code enter the Condition But that jQuery part make error. Thankfully Anes P.A Hi, i can't get my new logo to work in IE, it's working fine in Chrome and FireFox, it must be a JavaScript problem. here it is: http://danishwebart.com/logo/logo.php And the JavaScrip: $(function() { var canvas = $("#c"); var canvasHeight; var canvasWidth; var ctx; var dt = 0.1; var pointCollection; function init() { updateCanvasDimensions(); var g = [new Point(27, 34, 0.0, 1, "#ed9d33"), new Point(26, 38, 0.0, 1, "#d44d61"), new Point(25, 41, 0.0, 1, "#4f7af2"), new Point(22, 44, 0.0, 1, "#ef9a1e"), new Point(18, 46, 0.0, 2, "#4976f3"), new Point(12, 44, 0.0, 2.5, "#269230"), new Point(7, 41, 0.0, 2, "#1f9e2c"), new Point(5, 37, 0.0, 1, "#36b641"), new Point(4, 33, 0.0, 1, "#2e5def"), new Point(4, 29, 0.0, 1, "#d53747"), new Point(5, 25, 0.0, 1, "#eb676f"), new Point(6, 22, 0.0, 1, "#f9b125"), new Point(8, 19, 0.0, 1, "#de3646"), new Point(11, 16, 0.0, 1, "#5f8af8"), new Point(13, 14, 0.0, 1, "#efa11e"), new Point(16, 12, 0.0, 1, "#2e55e2"), new Point(19, 10, 0.0, 1, "#4167e4"), new Point(23, 8, 0.0, 1.5, "#4869e3"), new Point(28, 6, 0.0, 2, "#10a11d"), new Point(33, 5, 0.0, 2, "#cf4055"), new Point(38, 5, 0.0, 2, "#cd4359"), new Point(44, 6, 0.0, 3, "#ca273c"), new Point(51, 8, 0.0, 3, "#2650e1"), new Point(57, 11, 0.0, 3, "#4a7bf9"), new Point(63, 16, 0.0, 3.5, "#f47875"), new Point(68, 23, 0.0, 4, "#f36764"), new Point(71, 31, 0.0, 3.5, "#1d4eeb"), new Point(72, 38, 0.0, 3, "#698bf1"), new Point(72, 44, 0.0, 2.5, "#fac652"), new Point(72, 49, 0.0, 2, "#ee5257"), new Point(71, 54, 0.0, 2, "#5681f5"), new Point(70, 59, 0.0, 2, "#f8c247"), new Point(68, 64, 0.0, 2, "#4577f6"), new Point(65, 68, 0.0, 2, "#f7b326"), new Point(62, 72, 0.0, 2, "#facb5e"), new Point(59, 75, 0.0, 2, "#e02e3d"), new Point(55, 77, 0.0, 2, "#f16d6f"), new Point(53, 78, 0.0, 2.5, "#507bf2"), new Point(47, 79, 0.0, 3, "#5683f7"), new Point(40, 77, 0.0, 3.5, "#3158e2"), new Point(33, 74, 0.0, 3.5, "#f0696c"), new Point(27, 73, 0.0, 2.5, "#3769f6"), new Point(22, 73, 0.0, 2, "#6084ef"), new Point(19, 76, 0.0, 1.5, "#2a5cf4"), new Point(17, 79, 0.0, 1, "#f4716e"), new Point(25, 70, 0.0, 2, "#f8c247"), new Point(29, 67, 0.0, 2, "#ec4147"), new Point(33, 64, 0.0, 2, "#4876f1"), new Point(36, 59, 0.0, 2.5, "#2552ea"), new Point(38, 53, 0.0, 3, "#4779f7"), new Point(38, 46, 0.0, 3.5, "#4b78f1"), new Point(38, 38, 0.0, 3.5, "#4b78f1"), new Point(37, 31, 0.0, 2.5, "#4b78f1"), new Point(38, 25, 0.0, 2, "#4b78f1"), new Point(40, 20, 0.0, 2, "#4b78f1"), new Point(42, 16, 0.0, 1.5, "#4b78f1"), new Point(45, 14, 0.0, 1, "#4b78f1"), new Point(48, 12, 0.0, 1, "#4b78f1"), new Point(59, 82, 0.0, 1, "#ed9d33"), new Point(62, 80, 0.0, 1.5, "#d44d61"), new Point(66, 77, 0.0, 2, "#4f7af2"), new Point(70, 73, 0.0, 2, "#4976f3"), new Point(73, 69, 0.0, 2, "#269230"), new Point(76, 65, 0.0, 2, "#1f9e2c"), new Point(79, 60, 0.0, 2, "#36b641"), new Point(80, 55, 0.0, 1.5, "#2e5def"), new Point(81, 65, 0.0, 2.5, "#eb676f"), new Point(83, 71, 0.0, 3, "#f9b125"), new Point(84, 77, 0.0, 2.5, "#de3646"), new Point(82, 82, 0.0, 2, "#de3646"), new Point(88, 74, 0.0, 1.5, "#efa11e"), new Point(90, 70, 0.0, 1.5, "#2e55e2"), new Point(92, 66, 0.0, 1.5, "#4869e3"), new Point(93, 62, 0.0, 1.5, "#4869e3"), new Point(95, 53, 0.0, 1, "#10a11d"), new Point(95, 57, 0.0, 2, "#cf4055"), new Point(97, 62, 0.0, 2.5, "#cd4359"), new Point(100, 68, 0.0, 3, "#ca273c"), new Point(102, 74, 0.0, 2.5, "#2650e1"), new Point(101, 80, 0.0, 2, "#4a7bf9"), new Point(105, 78, 0.0, 1, "#f36764"), new Point(107, 75, 0.0, 1, "#1d4eeb"), new Point(109, 72, 0.0, 1, "#698bf1"), new Point(110, 69, 0.0, 1, "#fac652"), new Point(111, 66, 0.0, 1, "#ee5257"), new Point(112, 63, 0.0, 1, "#5681f5"), new Point(112, 60, 0.0, 1.5, "#f8c247"), new Point(112, 56, 0.0, 1.5, "#4577f6"), new Point(110, 52, 0.0, 2, "#f7b326"), new Point(107, 48, 0.0, 2.5, "#facb5e"), new Point(102, 45, 0.0, 2.5, "#e02e3d"), new Point(97, 43, 0.0, 2, "#f16d6f"), new Point(110, 83, 0.0, 1, "#507bf2"), new Point(112, 80, 0.0, 1, "#5683f7"), new Point(114, 77, 0.0, 1.5, "#3158e2"), new Point(116, 73, 0.0, 1.5, "#f0696c"), new Point(118, 69, 0.0, 1.5, "#3769f6"), new Point(119, 65, 0.0, 1.5, "#6084ef"), new Point(119, 61, 0.0, 1.5, "#2a5cf4"), new Point(119, 57, 0.0, 1.5, "#f4716e"), new Point(118, 53, 0.0, 1.5, "#f8c247"), new Point(116, 50, 0.0, 1, "#ec4147"), new Point(120, 51, 0.0, 1, "#4876f1"), new Point(123, 53, 0.0, 1, "#2552ea"), new Point(126, 55, 0.0, 1, "#4779f7"), new Point(129, 58, 0.0, 1.5, "#4b78f1"), new Point(132, 61, 0.0, 1.5, "#4b78f1"), new Point(135, 65, 0.0, 1.5, "#4b78f1"), new Point(138, 69, 0.0, 1.5, "#4b78f1"), new Point(140, 73, 0.0, 2, "#4b78f1"), new Point(142, 78, 0.0, 2, "#4b78f1"), new Point(143, 83, 0.0, 2, "#4b78f1"), new Point(121, 70, 0.0, 1, "#4b78f1"), new Point(124, 71, 0.0, 1, "#4b78f1"), new Point(127, 71, 0.0, 1, "#4b78f1"), new Point(130, 71, 0.0, 1.5, "#4b78f1"), new Point(134, 70, 0.0, 1.5, "#4b78f1"), new Point(142, 68, 0.0, 1.5, "#4b78f1"), new Point(146, 68, 0.0, 1, "#4b78f1"), new Point(149, 69, 0.0, 1, "#4b78f1")]; gLength = g.length; for (var i = 0; i < gLength; i++) { g[i].curPos.x = (canvasWidth/2 - 0) + g[i].curPos.x; g[i].curPos.y = (canvasHeight/2 - 0) + g[i].curPos.y; g[i].originalPos.x = (canvasWidth/2 - 0) + g[i].originalPos.x; g[i].originalPos.y = (canvasHeight/2 - 0) + g[i].originalPos.y; }; pointCollection = new PointCollection(); pointCollection.points = g; initEventListeners(); timeout(); }; function initEventListeners() { $(window).bind('resize', updateCanvasDimensions).bind('mousemove', onMove); canvas.get(0).ontouchmove = function(e) { e.preventDefault(); onTouchMove(e); }; canvas.get(0).ontouchstart = function(e) { e.preventDefault(); }; }; function updateCanvasDimensions() { canvas.attr({height: $(window).height(), width: $(window).width()}); canvasWidth = canvas.width(); canvasHeight = canvas.height(); draw(); }; function onMove(e) { if (pointCollection) pointCollection.mousePos.set(e.pageX, e.pageY); }; function onTouchMove(e) { if (pointCollection) pointCollection.mousePos.set(e.targetTouches[0].pageX, e.targetTouches[0].pageY); }; function timeout() { draw(); update(); setTimeout(function() { timeout() }, 30); }; function draw() { var tmpCanvas = canvas.get(0); if (tmpCanvas.getContext == null) { return; }; ctx = tmpCanvas.getContext('2d'); ctx.clearRect(0, 0, canvasWidth, canvasHeight); if (pointCollection) pointCollection.draw(); }; function update() { if (pointCollection) pointCollection.update(); }; function Vector(x, y, z) { this.x = x; this.y = y; this.z = z; this.addX = function(x) { this.x += x; }; this.addY = function(y) { this.y += y; }; this.addZ = function(z) { this.z += z; }; this.set = function(x, y, z) { this.x = x; this.y = y; this.z = z; }; }; function PointCollection() { this.mousePos = new Vector(0, 0); this.points = new Array(); this.newPoint = function(x, y, z) { var point = new Point(x, y, z); this.points.push(point); return point; }; this.update = function() { var pointsLength = this.points.length; for (var i = 0; i < pointsLength; i++) { var point = this.points[i]; if (point == null) continue; var dx = this.mousePos.x - point.curPos.x; var dy = this.mousePos.y - point.curPos.y; var dd = (dx * dx) + (dy * dy); var d = Math.sqrt(dd); if (d < 80) { point.targetPos.x = (this.mousePos.x < point.curPos.x) ? point.curPos.x - dx : point.curPos.x - dx; point.targetPos.y = (this.mousePos.y < point.curPos.y) ? point.curPos.y - dy : point.curPos.y - dy; } else { point.targetPos.x = point.originalPos.x; point.targetPos.y = point.originalPos.y; }; point.update(); }; }; this.draw = function() { var pointsLength = this.points.length; for (var i = 0; i < pointsLength; i++) { var point = this.points[i]; if (point == null) continue; point.draw(); }; }; }; function Point(x, y, z, size, colour) { this.colour = colour; this.curPos = new Vector(x, y, z); this.friction = 0.8; this.originalPos = new Vector(x, y, z); this.radius = size; this.size = size; this.springStrength = 0.1; this.targetPos = new Vector(x, y, z); this.velocity = new Vector(0.0, 0.0, 0.0); this.update = function() { var dx = this.targetPos.x - this.curPos.x; var ax = dx * this.springStrength; this.velocity.x += ax; this.velocity.x *= this.friction; this.curPos.x += this.velocity.x; var dy = this.targetPos.y - this.curPos.y; var ay = dy * this.springStrength; this.velocity.y += ay; this.velocity.y *= this.friction; this.curPos.y += this.velocity.y; var dox = this.originalPos.x - this.curPos.x; var doy = this.originalPos.y - this.curPos.y; var dd = (dox * dox) + (doy * doy); var d = Math.sqrt(dd); this.targetPos.z = d/100 + 1; var dz = this.targetPos.z - this.curPos.z; var az = dz * this.springStrength; this.velocity.z += az; this.velocity.z *= this.friction; this.curPos.z += this.velocity.z; this.radius = this.size*this.curPos.z; if (this.radius < 1) this.radius = 1; }; this.draw = function() { ctx.fillStyle = this.colour; ctx.beginPath(); ctx.arc(this.curPos.x, this.curPos.y, this.radius, 0, Math.PI*2, true); ctx.fill(); }; }; init(); }); I am creating a page which redirects automatically depending on the date. What I've done so far is below, but how would I make it go switch to exceeded_year.htm on 25th March 2011 for example? I will also include other dates and later put this page in a header frame and controlling the frame below so its constantly open. <html> <script type="text/javascript"> <!-- var currentTime = new Date() var date = currentTime.getDate() var month = currentTime.getMonth() + 1 var year = currentTime.getFullYear() if (year > 2011 ) {window.location = "exceeded_year.htm"; } else window.location="#" //--> </script> </html> For help I m putting it all together ..copy and paste and run ... I used 2 browsers IE and mozilla... you fill find the problem ...I know some one will definatly solve my problem ..... Code: <script type="text/javascript" language="JavaScript"><!-- function ManageTabPanelDisplay() { var idlist = new Array('tab1focus','tab2focus','tab3focus','tab4focus','tab1ready','tab2ready','tab3ready','tab4ready','content1','content2','content3','content4'); if(arguments.length < 1) { return; } for(var i = 0; i < idlist.length; i++) { var block = false; for(var ii = 0; ii < arguments.length; ii++) { if(idlist[i] == arguments[ii]) { block = true; break; } } if(block) { document.getElementById(idlist[i]).style.display = "block"; } else { document.getElementById(idlist[i]).style.display = "none"; } } } //--></script> <style type="text/css"> .tab { font-family: verdana,sans-serif; font-size: 12px; width: 100px; height:30px; white-space: nowrap; text-align: center; border-style: solid; border-color: #9a9a9a; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 0px; padding-top: 5px; padding-bottom: 5px; padding-left:3px; padding-right:3px; cursor: pointer; } .tabhold { background-color:#9a9a9a; /*color of menu #666666*/ color: white; } .tabfocus { background-color:white; color: #666666; } .tabcontent { font-family: sans-serif; font-size: 12px; height: 320px; border-style: solid; border-color: #9a9a9a; border-width: 1px; padding-top: 15px; padding-left: 10px; padding-right: 10px; overflow-y:scroll;overflow:-moz-scrollbars-vertical; } </style> <table border="0" cellpadding="0" cellspacing="0" > <tr > <td> <div id="tab1focus" class="tab tabfocus" style="display:block; padding-top:10px; height:39px;" > Overview </div> <div id="tab1ready" class="tab tabhold" style="display:none; padding-top:10px;height:39px;"> <span onclick="ManageTabPanelDisplay('tab1focus','tab2ready','tab3ready','tab4ready','content1')" >Overview </span> </div> </td><td > </td><td> <div id="tab2focus" class="tab tabfocus" style="display:none;"> Dimensions <br /> & Details </div> <div id="tab2ready" class="tab tabhold" style="display:block;"> <span onclick="ManageTabPanelDisplay('tab1ready','tab2focus','tab3ready','tab4ready','content2')">Dimensions <br /> & Details</span> </div> </td><td > </td><td> <div id="tab3focus" class="tab tabfocus" style="display:none;"> Quantity <br /> & Constructions </div> <div id="tab3ready" class="tab tabhold" style="display:block;"> <span onclick="ManageTabPanelDisplay('tab1ready','tab2ready','tab3focus','tab4ready','content3')">Quantity <br /> & Constructions</span> </div> </td> <td > </td><td> <div id="tab4focus" class="tab tabfocus" style="display:none;"> Customization <br /> Options </div> <div id="tab4ready" class="tab tabhold" style="display:block;"> <span onclick="ManageTabPanelDisplay('tab1ready','tab2ready','tab3ready','tab4focus','content4')">Customization <br /> Options </span> </div> </td> <td width="100%"> </td><td> </tr> <tr > <td colspan="8" > <div id="content1" class="tabcontent" style="display:block;"> content1 </div> <div id="content2" class="tabcontent" style="display:none;"> content2 </div> <div id="content3" class="tabcontent" style="display:none;"> content3 </div> <div id="content4" class="tabcontent" style="display:none;"> content4 </div> </td></tr> </table> please help thanks Code: <html> <head> <!-- CIS 340 Final Webpage project Author: Jeffrey Faulkner Date: 04/27/2011 File name: Mailinglist.htm --> <title>Home</title> <link href="mario.css" rel="stylesheet" type="text/css" /> <script src="random.js" type="text/javascript"></script> <script src="ads.js" type="text/javascript"></script> <script type="text/javascript"> function valmail() { var lastName = document.Infoform.LastName.value; var firstname = document.Infoform.FirstName.value; var mi = document.Infoform.Mi.value; var address = document.Infoform.Address.value; var city = document.Infoform.City.value; var state = document.Infoform.State.value; var zip = document.Infoform.Zip.value; var phone = document.Infoform.Phone.value; var dob = new Date (document.Infoform.Dob.value); var res = document.Infoform.chkResident.value; var email = document.infoform.email.value; var cemail = document.infoform.cemail.value; var stuClass; var classChecked = false; var selectnews = document.getElementById('lstF_ID'); var advisor = selectnews.options (selectnews.selectedIndex).innerHTML var radio = document.Infoform.Class.value; for (var i=0; i < document.Infoform.Class.length; i++) { if (document.Infoform.Class[i].checked) { classChecked = true; stuClass = document.Infoform.Class[i].value; } } if (lastName == "") { alert ("Please enter a last name"); document.Infoform.LastName.select(); return false; } else if (firstname == "") { alert ("Please enter a first name"); document.Infoform.FirstName.select(); return false; }else if (address == "") { alert ("Please enter a address"); document.Infoform.Address.select(); return false; } else if (city == "") { alert ("Please enter a city"); document.Infoform.City.select(); return false; } else if (state == "") { alert ("Please enter a state"); document.Infoform.State.select(); return false; } else if (zip == "") { alert ("Please enter a zip"); document.Infoform.Zip.select(); return false; } else if (phone == "") { alert ("Please enter a phone"); document.Infoform.Phone.select(); return false; }else if (dob == "NaN") { alert ("Date of Birth is not valid, use MM/DD/YYYY to enter data"); document.Infoform.Dob.select(); return false; }else if (Class.checked == "false"){ alert ("No class selected"); return false; }else if (email != cemail){ alert ("emails are not the same."); return false; }else { alert ("Last name: " + lastName + "\n" + "First Name: " + firstname + "\n" + "mi: " + mi + "\n" + "Address: " + address + "\n" + "City: " + city + "\n" + "State: " + state + "\n" + "Zip: " + zip + "\n" + "phone: " + phone + "\n" + "Date of Birth: " + dob + "\n" + "Advisor " + advisor + "\n" + "classfication " + stuClass); return true; } } </script> </head> <body> <h5><script type="text/javascript"> rNumber = randInt(5); //generate a random integer from 1 to 5 rAd = adDescription(rNumber); // description of the random ad rLink = adLink(rNumber); // url of the random ad document.write("<a href=" + rLink + ">"); document.write("<img src='ad" + rNumber + ".jpg' alt='" + rAd + "' />"); document.write("</a>"); </script></h5> <hr /> <a href="Home.htm">Home</a> <a href="speedrun.htm">Speed Runs</a> <a href="History.htm">History</a> <a href="mailinglist.htm">Mailing List</a> <a href="games.xml">List of games</a> <hr /> <h5><h3>Mario Mailing List</h3></h5> <h5><h3><form name="Infoform" action="action%20marker" id="Infoform" onSubmit="valmail()"> <table align="center"> <tr> <td> Last Name:</td> <td><input type="text" name="LastName" size="20" /></td> <td></td> <td></td> <td><h4>Class:</h4></td> <td></td> </tr> <tr> <td> First Name:</td> <td><input type="text" name="FirstName" size="20" /></td> <td></td> <td><input type="radio" name="Class" value="Mail" /></td> <td>Mail<td> </tr> <tr> <td> MI:</td> <td><input type="text" name="Mi" size="5" /></td> <td></td> <td><input type="radio" name="Class" value="email" /></td> <td>Email</td> </tr> <tr> <td> Address:</td> <td><input type="text" name="Address" size="20" /></td> <td></td> <td><input type="radio" name="Class" value="email" /></td> <td>phone</td> </tr> <tr> <td> City:</td> <td><input type="text" name="City" size="20" /></td> <td></td> <td><input type="radio" name="Class" value="text" /></td> <td>text</td> </tr> <tr> <td> State:</td> <td><input type="text" name="State" size="5" /></td> <td></td> <td><input type="radio" name="Class" value="any" /></td> <td>any</td> </tr> <tr> <td> ZIP Code:</td> <td><input type="text" name="Zip" size="20" /></td> <td></td> <td></td> <td></td> </tr> <tr> <td> Phone:</td> <td><input type="text" name="Phone" size="20" /></td> <td></td> <td><input name="chkResident" type="checkbox" /></td> <td> All the above</td> </tr> <tr> <td> Date of Birth:</td> <td><input type="text" name="Dob" size="20" /></td> <td></td> <td>What news do you want to here about?</td> <td><select size="1" name="lstF_ID"> <option selected="selected" value="1">New speed runs</option> <option value="2">upcoming games</option> <option value="3">New bugs found</option> <option value="4">new speed runs</option> <option value="5">All</option> </select value="1"></td> </tr> <tr> <td> EMail:</td> <td><input type="text" name="email" size="20" /></td> <td></td> <td></td> <td></td> </tr> <tr> <td> confirm email:</td> <td><input type="text" name="cemail" size="20" /></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td><input type="submit" value="Submit" /></td> </tr> </table> </form></h3></h5> </body> <hr /> <address> All information taken from mario wiki </address> </html> I have looked at this for an hour and i can not find anything wrong Hi, so I thought I could mash two bits of code together like this: Code: <div><label for="or">From:</label> <select name="or" style="width:200px; float: right" id="or" onchange="populate(this)"> <option value="Choose">Select your starting point</option> <option value="Guatemala">Guatemala City</option> <option value="Xela">Quetzaltenango</option> <option value="Antigua">Antigua</option> <option value="Rio Dulce">Rio Dulce</option> <option value="Coban">Coban</option> </select></div> <div> <label for="de">To:</label> <select name="de" style="width:200px; float: right" id="de"></select> </div> <div> <br> <input type="button" onclick="searchLocations()" value="Show route" /> </div> </div> </div> </div> <script type="text/javascript"> if (GBrowserIsCompatible()) { var gpolylines = []; function populate(o) { d=document.getElementById('de'); if(!d){return;} var mitems=new Array(); mitems['Choose']=['']; mitems['Guatemala']=['Select Destination','Antigua','El Rancho junction','San Pedro La Laguna','Panajachel','Coban','Rio Hondo','Chiquimula','Esquipulas','Copan Ruinas (Honduras)','La Ruidosa junction','Rio Dulce','Flores (via Rio Dulce)','Puerto Barrios','Flores (via Coban)','Quetzaltenango']; mitems['Xela']=['Select Destination','Guatemala City','Antigua','Chichicastenango','Huehuetenango','Panajachel','San Pedro La Laguna']; mitems['Antigua']=['Select Destination','Guatemala City','Quetzaltenango','Escuintla','Monterrico','San Pedro la Laguna','Panajachel','Chichicastenango']; mitems['Rio Dulce']=['Select Destination','Guatemala City','Flores','Lanquin','Coban','Puerto Barrios']; mitems['Coban']=['Select Destination','Lanquin','Rio Dulce','Laguna Lachua NP','Flores']; d.options.length=0; cur=mitems[o.options[o.selectedIndex].value]; if(!cur){return;} d.options.length=cur.length; for(var i=0;i<cur.length;i++) { d.options[i].text=cur[i]; d.options[i].value=cur[i]; } } function searchLocations() { var found = false; var from = document.getElementById('or').value; var to = document.getElementById('de').value; for (var a = 0; a < gpolylines.length; a++) { if (gpolylines[a].myname.toLowerCase() == to.toLowerCase() && gpolylines[a].mycategory.toLowerCase() == from.toLowerCase()) { found = true; gpolylines[a].show(); } } if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } the first bit, which populates the select boxes works fine, as you can see here but the second bit (the searchLocations function) is giving me a bit more trouble. What it's supposed to be doing is saying that if there's a polyline whose category xml attribute matches the text from the 1st select box AND whose name attribute matches the 2nd select box, it should be shown. The methods have worked in the past, there are no errors reported - the only problem is I get the alert regardless of which option I am selecting. I suspect that the problem is in the if (gpolylines[a].myname.toLowerCase() == to.toLowerCase() && gpolylines[a].mycategory.toLowerCase() == from.toLowerCase()) line, as it's the only one that I really came up with on my own... or can I not get the "or" and "de" elements in that way? Or is it something else entirely? thanks in advance for any suggestions... This is a program that calculates discriminant/number of solutions for a given quadratic equation.. it all works, but the number of solution field is not filled, so i think i did something wrong on my if else statements for it.. help! Code: <html> <head> <title>Untitled</title> </head> <script type="text/javascript"> <!-- Begin function quad(form) { a = form.a.value b = form.b.value c = form.c.value form.Dis.value = (b * b) - (4 * a * c) If(form.Dis.value > 0) { form.NumSol.value = 2 } Else;(form.Dis.value = 0) { form.NumSol.value = 1 } Else { form.NumSol.value = 0 } } // End --> </script> <body><center> <form name="form1"> <input type="text" name="a" size=5> x^2 + <input type="text" name="b" size=5> x + <input type="text" name="c" size=5> <input type="button" value="Calculate" onClick="quad(this.form)"> Discriminant: <input type="text" name="Dis" size = 7 /> Number of Solutions: <input type="text" name="NumSol" size = 7 /> </form> </center> </body> </html> Scratch that, its started working... oh well haha hi i found some javascript on the internet that seemed to do what I wanted to achieve but cannot get it to work when the mouse is over the image it should show a bigger image. I've used the internet explorer debugger and there seems to be problem in the code, but i dont understand javascript programming. Im a php man myself. all the script is enclosed in this page http://www.web-malta.com/testimage.html if you put the mouse over the photo you will see there is an error on the page. hope someonbe can help. cheers |