JavaScript - Need Simple Value Multiplier In Javascript
Hello everyone,
I need help i need to create a very simple multiplier in javascript to multiply two values like it should ask me first value then second and then show its result Thanks in advance Reply With Quote 01-13-2015, 02:33 PM #2 Dormilich View Profile View Forum Posts Senior Coder Join Date Jan 2010 Location Behind the Wall Posts 3,532 Thanks 13 Thanked 372 Times in 368 Posts what have you tried? Similar TutorialsHere is what i'm trying to do. Var x=0; var y=0; function go(){ // these two var are inputs. var run=get_form_value("run_fast"); var breath=get_form_value("take_a_breath"); x++; y++; run action; function (){ if (x<run) {go()} if(y==breath || (y==breath^2 || (y==breath^3))){drink();} }; This doesn't work but maybe you get the idea behind it. by the way when i run this version it will run all 20 times and it will take a breath at 5 but then for the remander of runs it takes a breath after every run after. assume that a person can only run 5 before taking a breath. inputs are (run_fast = 20) and (take_a_breath=5) The idea here is to run 20 times but take a drink after each set of 5 runs. the reason i have to do y= breath times 2 is because everyone is differant some can run 6 before a breath some only 4. can someone please help with this. i've worked on it all day and my head hurts from trying. 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, 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 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> 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". 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. 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. 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 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 am very new to coding. The below is an assignment for a class. It is a "game" which is supposed to do the following: When your program starts up it must display the image that will move around, a Start button, a Stop button, and a way for the user to specify an interval before a new game begins. The default interval must be 1000 msec. When the user presses Start, a new game starts and the selected image is displayed at a random place. The image must move to a new random place once per interval. If the user presses the Stop button, the image must stop moving, and a subsequent Start must start everything over from the beginning. Each time the user successfully hits the image, the program must move the image to a new random place immediately (i.e., not wait for the current interval to end). When the user has hit the image 3 times, the program must display a confirm dialog box that reports the elapsed time and that also says something like "Another game?" If the user pushes OK, that starts a new game immediately (no need to push Start again). If Cancel is pushed, the program stops. I have been working on this for hours, but it does not work properly. Obvious issues: the game starts running when the page loads, instead of when the start button is pushed. The confirm at the end does not cause a new game to start. The time/ elapsed time calculations are not functioning properly/ the elapsed time always displays as 1 sec. Code: <html> <title> Dori's WhaM Game </title> <head> Stephen Salutes You </head> <body> <br> <img id="Colbert" src="StephenColbert.jpeg" style="position:absolute; left:10px; top:85px" onClick='hit()'> <form> <input type=button value="Start game." onClick='newgame()'> <input type=button value="Stop it, stop it now." onClick='clearInterval(setint_val); return true;'> <br> Desired speed is <input type=text id=interval value="1000" size=5> msec </form> <script> var hitcount= 0 var setint_val = (setInterval('moveit()', document.getElementById("interval").value)); var starttime var endtime function newgame() { clearInterval(setint_val) hitcount= 0 setInterval() starttime=new Date().getTime() } function moveit() { document.getElementById("Colbert").style.left = 800 * Math.random() + "px"; document.getElementById("Colbert").style.top = 500 * Math.random() + "px"; } function hit() { moveit() clearInterval(setint_val) setInterval() hitcount= hitcount + 1 if (hitcount >= 3) { clearInterval (setint_val); // clearInterval() to stop the image from moving endtime=new Date().getTime(); alert(starttime) alert (endtime) // compute the elapsed time (make another call to new Date()) if (confirm("That took " + endtime-starttime+" seconds. Would you like to try again?")) { newgame ()} else {clearInterval (setint_val) hitcount=0} }} </script> </body> </html> Hi, I have just started to learn Javascript which when loaded into a safari web browser of Firefox browser just simply displays the code. I am currently using a MacBook Leopard operating system I have saved the code (corrected for mistakes, many many times) to my desktop Run my usual browser safari (and tried same with Firefox) loaded the file and all I get is a copy of the code displayed in the browser window. Javascript is enabled for both Please can you suggest some options for me to try and get the code working. All I am doing in this example is copied from a book to turn the background colour of the browser RED Thanks Tom 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> 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'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? 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 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 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 I have a page with options, and I need to hide options unless a certain choice is selected. So say you have a select box for male and female, if they select male, I need it to show male options, and if they select female, it shows female options. How can I hide things until selected and then show the textboxes and stuff? Thank you! |