JavaScript - Help With Simple Javascript Simple Converter
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 Similar TutorialsHey 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> 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. 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! This is my first post here. I am not a programmer and I thought you guys would be able to help me. I have this script in one of my pages. It was written by a former coworker. It worked perfectly in Firefox 3.6 but stopped working after browser upgrades. It may be a simple fix... I just don't know. Any help would be GREATLY appreciated. Here is the code in the HEAD: Code: <script type="text/javascript"> function generateAnswer() { //alert("answersheet"); window.open("answerSheet.html" + window.location.search); } </script> And here is the code in the BODY, where the script is called: Code: <p>Generate the answer sheet for the tests you have selected: <a href="javascript:generateAnswer()">Generate</a></p> When the page runs, I can see the "Generate" link, but it takes me nowhere. i have this simple js example to click Delete Post and then give the user two options. If they click yes then they go that page...but how do i set it to where when they click cancel it goes back to "Delete Post" ??? i suck at javascript Code: <html> <body> <p><b>Delete Post</b></p> <script type="text/javascript"> window.onclick=function(){ document.getElementsByTagName("p")[0].innerHTML="<b><a href='#'>Delete</a> || Cancel</b>" } </script> </body> </html> I'm trying to code a set of buttons that upon being pressed, change an image on the other side of the table in which they're located (not themselves). Is there a way to do this and if so, what would it be? So far I've been trying to use onMouseDown and changeImage with object id tags to get the effect but it's not working. I'm brand new to javascript and have a simple assignment that I'm stuck on. I would appreciate any help. Here's what I want: 0:0 1:1 2:3 3:6 4:10 5:15 As you can see, I want the numbers after the colon to be a sum of the number to the left and the number above it. I can easily get the number before the colon, but not sure how to get the sum (the number after the semicolon). Here's my code so far: <html> <body> <script type="text/javascript"> N=0; while (N<=5) { document.write(+ N); N++; document.write(":"); document.write("<br />"); } </script> </body> </html> I need to use a loop, hence the "while" loop. But not sure how to set up variables to do the addition. Thanks much for any help - as you can see, I'm not a programmer. Can anyone help me with doing this? I'm kinda new to JavaScript! Create an Array (list) containing 10 words. For every half second going word by word appears in a <span> element. When all the words in the list are gone through, the interval shall stop and printing "The End". Hi guys, I have this piece of php code: PHP Code: <?php $file = 'counter.txt'; $data = @file($file); $data = $data[0]; if($handle = @fopen($file, 'w')){ $data = intval($data); $data++; fwrite($handle, $data); fclose($handle); } ?> What I need to know is, can javascript activate this piece of php code with an onclick function to make it write to the txt file? I have a link that downloads a file and would like to add a little javascript onclick function to write to the text file (as in the php code above) at the same time as they download the file. I was not sure if this was possible in the same way you would do something like: window.location.href='http://www.yoursite.com'; Any help is hugly appreciated. Kind regards, paffley Hi, I have some Javascript, what I want to hapen is, when the variables hour and randomhour are the same, the message hello is displayed. What actually happens is the message will display all the time, and dissapear when randomhour is 0. Here is my script: Code: <script type="text/javascript"> //Gets hour and minute of day var d = new Date(); var hour = d.getHours(); var minute = d.getMinutes(); //Generates a random hour and minute var randomhour=Math.floor(Math.random()*24) var randomminute=Math.floor(Math.random()*60) document.write(hour); document.write(minute); document.write("----"); document.write(randomhour); document.write(randomminute); if (hour = randomhour) { document.write("<b>Hello</b>"); } </script> i want a simple javascript countdown that counts down from 10 seconds to 0 and does NOTHING ELSE. im redirecting the page with a meta refresh and i want users to know when they'll be redirected, but most of the scripts found online have either minutes, hours, or days in them or have a javascript countdown after it's finished, which i don't want either since i'm doing a meta refresh. i know making something like this isnt rocket science but i know almost NOTHING about javascript Hey guys, I'm new to javascript and I'm trying to get this code to work. It's a pretty basic system to start with, just wanting to calculate the total pay for employees and using the array so that I can key multiple employees at a time. Can anyone help me adjust my code so that this system works? Thanks for your help in advance, it's greatly appreciated. Code: var NoEmps var PayRate= new Array(); var HrsWorked= new Array(); var EmpName= new Array(); var GrossPay= new Array(); var i var j NoEmps=prompt("Enter Number of Employees to process","") i = 0; while (i<NoEmps) { EmpName[i]= prompt("Enter employee name","") PayRate[i]=prompt("Enter employee pay rate","") HrsWorked[i]= prompt ("Enter hours worked","") if ((isNaN(PayRate[i]))||(isNaN(HrsWorked[i]))) { alert("Please enter numbers") flag = "false" break } if PayRate[i]>25 { alert ("Pay rate can only b $25 or less per hour") flag == "false" break } //i = i +1 } if (flag = "true") { for (j in EmpName) { GrossPay[j]=PayRate[j] * HrsWorked[j] } for (counter; counter<EmpName.length; counter++) { document.write ("Gross Pay for " + EmpName[counter] + " is $" + GrossPay[counter] + "<br>") } } Hi everyone, I am new to javascript, i have not read any books, but i am trying to figure out the language on the go. I am stuck with a simple program that i am trying to create for a class project. Any suggestions or help would much appreciated. My code is very simple in which i would like to convert a number value into different format of temperature. My code is listed below, it is not working in the browser. Help me fix it. ********************************************************* <!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 content="text/html" http-equiv="Content-Type" /> <title>E6B temp conversion</title> <script type="text/javascript"> function ConvertTempToC(TempConversionC) { var temperature = TempConversionC.F.value; if (temperature.length > 0) { TempConversionC.TempC.value = Math.round(5/9 * (temperature - 32)); document.write(TempConversionC.TempC.value); } } </script> </head> <body> <b>Fahrenheit to Celsius</b> <br/> <input size="6" name="F"/> <br/> <input onclick="ConvertTempToC(this.form)" value="Calculate Celsius" type="button" name="Submit11"/> <br/> <input readonly="readonly" size="6" name="TempC"/> </body> </html> I have a script that includes a JS delete function, but when I select a record and hit delete it says no record is selected. I'm sure this is a simple fix for someone in the know. Thanks in advance. Site: PHP Code: <?php require_once('auth.php'); ?> <script type="text/javascript" src="script.js"> </script> <?php include("header.php"); ?> <b><div align="right"><a href="admin-index.php">Admin</a> - <a href="adminorders.php">Orders</a> - <a href="adminmain_forum.php">Support</a> - <a href="register-form.php">Add User</a> - <a href="adminlogout.php">Logout</a></div></b><br> <b>Report Upload</b> <br>To upload reports after completion use the form below and update the order with the report URL (/reports/filename). <center><form action="./uploadadmin.php" method="post" enctype="multipart/form-data"> <p> <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br /> <p><button>Upload File</button> <p> </form></center> <p><b>Previous Orders</b> <br>Details of previous orders and trials are displayed below. <br><script> <!-- Hide from old browsers /****************************************** * Find In Page Script -- Submitted/revised by Alan Koontz (alankoontz@REMOVETHISyahoo.com) * Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code * This notice must stay intact for use ******************************************/ // revised by Alan Koontz -- May 2003 var TRange = null; var dupeRange = null; var TestRange = null; var win = null; // SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT // http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html var nom = navigator.appName.toLowerCase(); var agt = navigator.userAgent.toLowerCase(); var is_major = parseInt(navigator.appVersion); var is_minor = parseFloat(navigator.appVersion); var is_ie = (agt.indexOf("msie") != -1); var is_ie4up = (is_ie && (is_major >= 4)); var is_not_moz = (agt.indexOf('netscape')!=-1) var is_nav = (nom.indexOf('netscape')!=-1); var is_nav4 = (is_nav && (is_major == 4)); var is_mac = (agt.indexOf("mac")!=-1); var is_gecko = (agt.indexOf('gecko') != -1); var is_opera = (agt.indexOf("opera") != -1); // GECKO REVISION var is_rev=0 if (is_gecko) { temp = agt.split("rv:") is_rev = parseFloat(temp[1]) } // USE THE FOLLOWING VARIABLE TO CONFIGURE FRAMES TO SEARCH // (SELF OR CHILD FRAME) // If you want to search another frame, change from "self" to // the name of the target frame: // e.g., var frametosearch = 'main' //var frametosearch = 'main'; var frametosearch = self; function search(whichform, whichframe) { // TEST FOR IE5 FOR MAC (NO DOCUMENTATION) if (is_ie4up && is_mac) return; // TEST FOR NAV 6 (NO DOCUMENTATION) if (is_gecko && (is_rev <1)) return; // TEST FOR Opera (NO DOCUMENTATION) if (is_opera) return; // INITIALIZATIONS FOR FIND-IN-PAGE SEARCHES if(whichform.findthis.value!=null && whichform.findthis.value!='') { str = whichform.findthis.value; win = whichframe; var frameval=false; if(win!=self) { frameval=true; // this will enable Nav7 to search child frame win = parent.frames[whichframe]; } } else return; // i.e., no search string was entered var strFound; // NAVIGATOR 4 SPECIFIC CODE if(is_nav4 && (is_minor < 5)) { strFound=win.find(str); // case insensitive, forward search by default // There are 3 arguments available: // searchString: type string and it's the item to be searched // caseSensitive: boolean -- is search case sensitive? // backwards: boolean --should we also search backwards? // strFound=win.find(str, false, false) is the explicit // version of the above // The Mac version of Nav4 has wrapAround, but // cannot be specified in JS } // NAVIGATOR 7 and Mozilla rev 1+ SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6) if (is_gecko && (is_rev >= 1)) { if(frameval!=false) win.focus(); // force search in specified child frame strFound=win.find(str, false, false, true, false, frameval, false); // The following statement enables reversion of focus // back to the search box after each search event // allowing the user to press the ENTER key instead // of clicking the search button to continue search. // Note: tends to be buggy in Mozilla as of 1.3.1 // (see www.mozilla.org) so is excluded from users // of that browser. if (is_not_moz) whichform.findthis.focus(); // There are 7 arguments available: // searchString: type string and it's the item to be searched // caseSensitive: boolean -- is search case sensitive? // backwards: boolean --should we also search backwards? // wrapAround: boolean -- should we wrap the search? // wholeWord: boolean: should we search only for whole words // searchInFrames: boolean -- should we search in frames? // showDialog: boolean -- should we show the Find Dialog? } if (is_ie4up) { // EXPLORER-SPECIFIC CODE revised 5/21/03 if (TRange!=null) { TestRange=win.document.body.createTextRange(); if (dupeRange.inRange(TestRange)) { TRange.collapse(false); strFound=TRange.findText(str); if (strFound) { //the following line added by Mike and Susan Keenan, 7 June 2003 win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop; TRange.select(); } } else { TRange=win.document.body.createTextRange(); TRange.collapse(false); strFound=TRange.findText(str); if (strFound) { //the following line added by Mike and Susan Keenan, 7 June 2003 win.document.body.scrollTop = TRange.offsetTop; TRange.select(); } } } if (TRange==null || strFound==0) { TRange=win.document.body.createTextRange(); dupeRange = TRange.duplicate(); strFound=TRange.findText(str); if (strFound) { //the following line added by Mike and Susan Keenan, 7 June 2003 win.document.body.scrollTop = TRange.offsetTop; TRange.select(); } } } if (!strFound) alert ("Order '"+str+"' not found!") // string not found } // --> </script> <!-- EXAMPLE FORM OF FIND-IN-PAGE SEARCH USING SUBMIT (ALLOWING 'ENTER/RETURN' KEY PRESS EVENT) --> <center><b>Enter order number</b> <form name="form1" onSubmit="search(document.form1, frametosearch); return false"><input type="text" name="findthis" size="15" title="Press 'ALT s' after clicking submit to repeatedly search page"> <input type="submit" value="Search Orders" ACCESSKEY="s"></form></center> <br><br><table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td> <form action="" method="post" name="" id=""> <table width="600" border="1" align="center" cellpadding="2" cellspacing="2"> <tr> <td><input name="topcheckbox" type="checkbox" class="check" id="topcheckbox" onClick="selectall();" value="ON"> Select All </td> <td colspan="4" align="center"><a href="form.php?mode=add">Add New Order</a></td> </tr> <tr> <td><strong><a href="javascript:goDel()">Delete</a></strong></td> <td><strong>Order Number</strong></td> <td><strong>Order Status</strong></td> <td><strong>Payment Status</strong></td> <td><strong>Update</strong></td> </tr> <? include("conn.php"); $sql="select sn,branchname,shortname,payment from $branch order by sn"; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { ?> <tr> <td><input name="<? echo $row['sn']; ?>" type="checkbox" class="check"></td> <td><? echo $row['branchname']; ?></td> <td><? echo $row['shortname']; ?></td> <td><? echo $row['payment']; ?></td> <td><a href="<? echo "form.php?sn=".$row['sn']."&mode=update"; ?>">Update</a></td> </tr> <? } ?> <tr> <td><strong><a href="javascript:goDel()">Delete</a></strong></td> <td><strong>Order Number</strong></td> <td><strong>Order Status</strong></td> <td><strong>Payment Status</strong></td> <td><strong>Update</strong></td> </tr> </table> </form></td> </tr> </table> <?php include("footer.php"); ?> JS File Code: function goDel() { var recslen = document.forms[0].length; var checkboxes="" for(i=1;i<recslen;i++) { if(document.forms[0].elements[i].checked==true) checkboxes+= " " + document.forms[0].elements[i].name } if(checkboxes.length>0) { var con=confirm("Are you sure you want to delete"); if(con) { document.forms[0].action="delete.php?recsno="+checkboxes document.forms[0].submit() } } else { alert("No record is selected.") } } function selectall() { // var formname=document.getElementById(formname); var recslen = document.forms[0].length; if(document.forms[0].topcheckbox.checked==true) { for(i=1;i<recslen;i++) { document.forms[0].elements[i].checked=true; } } else { for(i=1;i<recslen;i++) document.forms[0].elements[i].checked=false; } } I am in a basic computer science class. I have to do a simple javascript project, but some of the code isn't working. The popup works, but the button does not appear, and I cannot get my rollover image to appear. 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> </head> <h1>Money</h1> <script> function checkAGE(){if (!confirm ("Are you sure you want to enter? (<-- You can say whatever you want.)")) history.go(-1);return " "} document.writeln(checkAGE()) </script> <script type="text/javascript"> <p>If you want to make Green, then you need to see Green!</p> <FORM> <INPUT type="button" value="Change to Green!" name="button3" onClick="document.bgColor='green'"> <br> </FORM> Rollimage = new Array() Rollimage[0]= new Image(121,153) Rollimage[0].src = "http://news-libraries.mit.edu/blog/wp-content/uploads/2008/01/money.jpg" Rollimage[1] = new Image(121,153) Rollimage[1].src = "http://encefalus.com/wp-content/uploads/2008/09/resources_money.jpg" function SwapOut(){ document.Rupert.src = Rollimage[1].src; return true; } function SwapBack(){ document.Rupert.src = Rollimage[0].src; return true; } // - stop hiding --> </SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFFF"> <P align="center"> <A HREF="http://www.joemaller.com/" onmouseover="SwapOut()" onmouseout="SwapBack()"> <IMG SRC="joe_open.jpg" NAME="Rupert" WIDTH=121 HEIGHT=153 BORDER=0> </A> </P> </body> </html> I have a list with two items: Code: <select name="gateway" id="gateway"> <option value="2">PayPal</option> <option value="1">Credit/Debit Card</option> </select> When the second list item is selected, a div with several input fields needs to appear: Code: <div id="hidden_field"> Input fields are placed here. </div> Likewise, if someone selects the first list item, the div should not appear. Does anyone know how to do this with javascript? I am very new to javascript, so your help is greatly appreciated! I'm sure this is a simple thing to do, but I know next to zero javascript and can't find an example online. What I want to do is to toggle a number on a webpage when a user clicks a link. So ideally there would be a "click to toggle" link, and then a number (lets say 400), when the user clicks that toggle link the number would change to 800 (or whatever my variable is set to), when they click it again it would go back to that original number (in this case 400). Would someone be kind enough to help me with this? Thanks Hello guys, Im new to Javascript,please help me ya in my php code, I retrieve a ID value and assign to variable like below PHP Code: $id = $gettingdata['id']; and I want this id to be include together with javascript "insertsubcat" function like below Code: <a href="javascript:insertsubcat('.$ID.');"/>Click to insert this data</a> in the javascript page, I dont know how to call back the id value and i try like code below but it doesnt work Code: function insertsubcat(data) { var data = data.value; . . . . } Any idea? Thanks Azhan Malaysia I'm new to javascript but not to programming. Here is my code: PHP Code: PHP Code: print "<form name='goldcalculator'>"; print "<input type='hidden' name='goldspot' value='$goldvalue'>"; print "<select name='gunit' onchange='updateTotal();'>"; print "<option value='20'>Pennyweight (DWT)</option>"; print "<option value='31.1'>Grams (g)</option>"; print "</select><br>"; print "10K <input type='text' name='10k' onchange='updateTotal();'><br>"; print "14K <input type='text' name='14k' onchange='updateTotal();'><br>"; print "18K <input type='text' name='18k' onchange='updateTotal();'><br>"; print "22K <input type='text' name='22k' onchange='updateTotal();'><br>"; print "24K <input type='text' name='24k' onchange='updateTotal();'><br>"; print "TOTAL <input type='text' name='totalprice'>"; print "</form>"; Code: <script language="JavaScript"> function updateTotal() { var u = document.goldcalculator.gunit.value; var spotprice = document.goldcalculator.goldspot.value / u; var gold10 = document.goldcalculator.10k.value; var gold14 = document.goldcalculator.14k.value; var gold18 = document.goldcalculator.18k.value; var gold22 = document.goldcalculator.22k.value; var gold24 = document.goldcalculator.24k.value; var calculatedPrice = document.goldcalculator.totalprice.value; calculatedPrice = ((spotprice*.999*gold24)+(spotprice*.916*gold22)+(spotprice*.75*gold18)+(spotprice*.585*gold14)+(spotprice*.417*gold10)); } </script> I don't know where to begin to debug this. It's very simple. The $goldvalue variable is non-editable and is pulled off my MySQL database and that works. They fill in the inputs via the PHP form and then it basically adds them up and spits out the total. Can someone tell me what's wrong? |