JavaScript - Javascript Multiply Help Needed
Hi,
At www.happydaysremovals.com.estimatenew.html. Users fill in a form which has items of furniture, so they enter a number next to each item of furniture. The HTML uses text fields. When the form is submitted, the form is submitted to a php script that emails the results to myself. I am trying to also have a javascript function which runs before the php script runs. This javascript works out the cubic footage of all the items. If a user put "3" in the sofa text field, and I have defined that a sofa is 45 cubic feet, then the javascript will multiply 3 * 45. It will do a similar thing for all items of furniture, then add them all up to give a total cubic feet. I want that total field to then sent as a variable to the php script, along with all the other variables. My code so far (which doesnt work) Code: <script language="JavaScript"> function calculate() { var sofa_3_seater = document.getElementById('sofa_3_seater').value*45; var sofa_2_seater = document.getElementByID('sofa_2_seater').value*30; var armchair_large = document.getElementByID('armchair_large').value*15; var total=sofa_3_seater+sofa_2_seater+armchair_large; document.getElementByID('total').value = total; } </script> I have used a hidden field for the total value: Code: <input type="hidden" name="total" value=""> I want the javascript result to change the value of the hidden field that is called total. THen I want it all to be posted to the PHP script and email everything to me, including this newly calculated total field! THanks Similar TutorialsHi im new in javascript and im having some problems with the two dimensional arrays problems. Well basically what i need to do in this program its to multiply two matrices of the same length and print the result as a matrix Example [2 4] * [3 8] = [14 20] [3 2] [2 1] [13 26] I hope someone could help me im really stuck in this problem Code: <script> // Declared Constants MORSE_ALPHABET = new Array ( '.-', // A '-...', // B '-.-.', // C '-..', // D '.', // E '..-.', // F '--.', // G '....', // H '..', // I '.---', // J '-.-', // K '.-..', // L '--', // M '-.', // N '---', // O '.--.', // P '--.-', // Q '.-.', // R '...', // S '-', // T '..-', // U '...-', // V '.--', // W '-..-', // X '-.--', // Y '--..' // Z ); CHAR_CODE_A = 65; var CTS = prompt('Enter Morse code','here') var inMessage = CTS.split(' '); searchLocation(inMessage,MORSE_ALPHABET) function searchLocation(targetValue, arrayToSearchIn) { var searchIndex = 0; // Iterative counter for(i=0;i < targetValue.length;) { targetValue = targetValue[i]; // Search until found or end of array while( searchIndex<arrayToSearchIn.length && i != targetValue.length && arrayToSearchIn[searchIndex]!=targetValue ) { i++ searchIndex++; } if(searchIndex<arrayToSearchIn.length) { return String.fromCharCode(CHAR_CODE_A + searchIndex); } else { return -1; } } } document.writeln(searchLocation(inMessage,MORSE_ALPHABET)); </script> <head> </head> <body> </body> This is my code and i have figured it to create an array from the prompt and then use the function to return the first array it finds but i cant seem to make it go on to the next index of the array. I know that when you return a value the function closes and i have tried to store my return in a variable but its not working the way i want it to or I'm not writing the correct command or is there away to do multiply returns, i think what i need to do is simply but i have been staring at this screen for a while now and just cant see it. Please help me. Thanks I keep getting 28 when I am suppose to get 22 because of Order of Operations. Code: <html> <head> <title>Movie</title> <script type="text/javascript"> function ticketOrder() { var cost; var ticket; if(document.movieTicket.radTicket[0].checked) { ticket=document.movieTicket.radTicket[0].value; ticket=parseInt(ticket); cost=cost*ticket; } if(document.movieTicket.radTicket[1].checked) { ticket=document.movieTicket.radTicket[1].value; ticket=parseInt(ticket); cost=cost*ticket; } if(document.movieTicket.radReward[0].checked) { cost=document.movieTicket.radReward[0].value; cost=parseInt(cost); } else if(document.movieTicket.radReward[1].checked) { cost=document.movieTicket.radReward[1].value; cost=parseInt(cost); } if(document.movieTicket.chkPopcorn.checked) { var popcorn=document.movieTicket.chkPopcorn.value; popcorn=parseInt(popcorn); cost=cost+popcorn; } if(document.movieTicket.chkSoda.checked) { var soda=document.movieTicket.chkSoda.value; soda=parseInt(soda); cost=cost+soda; } if(document.movieTicket.chkCandy.checked) { var candy=document.movieTicket.chkCandy.value; candy=parseInt(candy); cost=cost+candy; } alert(cost*ticket); } </script> </head> <body> <div id="Header"> <h2>The Chicago Movie Palace</h2> </div> <form name="movieTicket"> How many tickets would you like to order?<br /> 1 Ticket<input type="radio" name="radTicket" value="1" /><br /> 2 Tickets<input type="radio" name="radTicket" value="2" /><br /> 3 Tickets<input type="radio" name="radTicket" value="3" /><br /> 4 Tickets<input type="radio" name="radTicket" value="4" /><br /> 5 Tickets<input type="radio" name="radTicket" value="5" /><br /> Are you a member of our theater?<br /> Yes<input type="radio" name="radReward" value="8" /><br /> No<input type="radio" name="radReward" value="10" /><br /> Would you like any food or drinks with your movie?<br /> Popcorn ($4)<input type="checkbox" name="chkPopcorn" value="4" /><br /> Soda ($3)<input type="checkbox" name="chkSoda" value="3" /><br /> Candy ($3)<input type="checkbox" name="chkCandy" value="3" /><br /> Which movie would you like to see? <select name="selUpcomingMovie"> <option value="Immortals">Immortals</option> <option value="J Edgar">J Edgar</option> <option value="Sherlock Holmes:A Game of Shadows" >Sherlock Holmes:A Game of Shadows</option> </select> <p><input type="button" name="btnSubmit" value="Order Tickets" onclick="ticketOrder()" /></p> </form> </body> </html> Need a little help with the final code on my project. I'm multiplying 3 drop downs to give me a total sq ft. I then want to take that variable and multiply it by a fixed number. i.e. qty*width*length equals a total of 8 sq ft, then take that 8 and multiply it by a fixed number (8*1.75), I want it to calculate without any submit buttons and show the total sq ft and the final value. thanks in advance for any assistance. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=unicode"> <form> <meta content="MSHTML 6.00.2900.5921" name="GENERATOR"></head> <body><strong>Quantity:</strong> <select id="qty" onchange="Calculate();" size="1" name=qty><option value="1" selected>1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value=5>5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value=10>10</option> <\SELECT></select> <strong>Banner Width:</strong> <select id="height" onchange="Calculate();" size="1" name=height><option value="2" selected>2</option> <option value="3">3</option> <option value="4">4</option> <\SELECT></select> <strong>Banner Length:</strong> <select id="length" onchange="Calculate();" size="1" name="length"><option value="4" selected>4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <\SELECT></select> <strong>Total sq ft: <font size=4><label id="lblRes"><!-- a Label to locate result in it -->8 </label></form></font></span></span></font> <p></p></span></span></font></font></strong> <div></div> <script language="javascript"> function Calculate() { var h = document.getElementById('height').value; var l = document.getElementById('length').value; var q = document.getElementById('qty').value; var result = h * l * q; document.getElementById('lblRes').innerHTML = result; } </script> </font></strong></body></html> Hi all, I am in the process of developing a calculator for some of my colleagues to use. One of the variables within the calculations is called PMH. I want to determine the value of PMH based on which checkboxes are ticked. Each checkbox has a different value. If the checkbox is not ticked, then the value of each option is 1 and obviously more than one checkbox may be ticked. I have created the checbox code: Code: <td><input type="checkbox" name="PMH" value="1.6" /> Smoker<br /> <input type="checkbox" name="PMH" value="0.4" /> CCF<br /> <input type="checkbox" name="PMH" value="0.5" /> Pulmonary Oedema / Cirrhosis<br /> <input type="checkbox" name="PMH" value="0.8" /> COAD<br /></td> but I have no idea on how to calculate what I need for var PMH. Can someone guide me as to what I need to do please? Cheers, mads Hi all... i need to auto calculate 3 fields and store the result in 2 fields: field 3 = field 1 * field 2 field 5 = (field 1 * field 2) - field 4 or field 3 - field 4 so far i'm trying to modify an existing code but i'm still can't get it working correcly Code: <html> <head> <script type="text/javascript"> function compute(inputObj, otherInputID, multiID, subID, diffID) { var otherObj = document.getElementById(otherInputID) var multiObj = document.getElementById(multiID) var subObj = document.getElementById(subID) var diffObj = document.getElementById(diffID) var v1=inputObj.value var v2=otherObj.value var v3=multiObj.value var v4=subObj.value var val1 = v1=="" ? 0 : parseFloat(v1) // convert string to float var val2 = v2=="" ? 0 : parseFloat(v2) var val3 = v3=="" ? 0 : parseFloat(v3) var val4 = v4=="" ? 0 : parseFloat(v4) multiObj.value = val1 * val2 diffObj.value = (val1 * val2)-val4 } </script> </head> <body> Value 1: <input id="txt1" type="text" onKeyUp="compute(this, 'txt2', 'addres', 'subtract', 'mulres')"> <br /> Value 2: <input id="txt2" type="text" onKeyUp="compute(this, 'txt1', 'addres', 'subtract', 'mulres')"> <br /> Added Result: <input id="addres" type="text"> <br /> substract: <input id="subtract" type="text" onKeyUp="compute('txt1', 'txt2', 'addres', this, 'mulres')"> <br /> Multiplied Result: <input id="mulres" type="text"> </body> </html> my problem is the Multiplied Result field not automatically change the result when i enter value in subtract field. it will change if i retype the value in field 1 and 2. Hope somebody can help me. Thank in advance I'm still a beginner in js core so please forgive if the question is too fundamental. In the following example PositionedRectangle is a subclass of Rectangle, all 3 methods of prototype inheritance seem to produce the same results, method 1 is from the authors book (Flanagan's Definitive Guide 5ed) example 9-3, and method 2 is from his website example 9-3, and method 3 is my own; Code: // method 1 seems most complicated function heir(p) { function f(){}; f.prototype =p; return new f(); } PositionedRectangle.prototype = heir(Rectangle.prototype); //method 2 PositionedRectangle.prototype = new Rectangle(); //method 3 seems most straight forward (I don't know if it's correct but works ok) PositionedRectangle.prototype = Rectangle.prototype; Thank you Gents, J. How to create a popup blocker with javascript? I am looking for solution to open Enquiry form [Ex: send-query.php] through javascript linking. How can I do that? And how to display a popup blocker message like in the attached file? This is the url of my pop up image: http://www.rhapsody.com/thompson-squ...mpson-square-2 [When you click on play button then if you have popup blocker enabled you will get popup blocker message from the site] I'm working very hard to create a dynamic web-site for use in the education sector using server-side php/MySQL and client-side HTML with javascript. I have a logon page (index.php) which looks to see if the cookie 'mylogon' is set with the value 'Again'. This cookie is set when the PHP element on the server detects an invalid username/password combination. If so I have a javascript function (see below) call from the HTML <body onload="check_invalid_user()"> I know that the function Get_Cookie is working ok and that the javascript variable 'again' has the value 'Again' in it and has a length of 5. The alert function is not executed though. function check_invalid_user() { again = Get_Cookie('mylogon'); // document.write(again); // document.write(again.length); If (again == 'Again') { alert("User-id and/or password incorrect -- Please re-enter"); } } ============= Any help would be appreciated Many thanks in advance. (Yeah you guessed it I'm new and raw to this stuff. I have a script that works good, but it says undefined underneath, this must mean an error. But I cant work out how to get rid of it. This is the html it is a transistional XHTML doc type. Code: <div id="slidedom"> <script type="text/javascript" src="js-files/slider.js"></div></script> Then I have the js file which I will have to post all of as I am not sure of the error bit. Code: var variableslide=new Array() //variableslide[x]=["path to image", "OPTIONAL link for image", "OPTIONAL text description (supports HTML tags)"] variableslide[0]=['images/sign-1.gif'] variableslide[1]=['images/sign-3.gif'] variableslide[2]=['images/sign-4.gif'] //configure the below 3 variables to set the dimension/background color of the slideshow var slidewidth='188px' //set to width of LARGEST image in your slideshow var slideheight='60px' //set to height of LARGEST iamge in your slideshow, plus any text description var slidebgcolor='#FFF' //configure the below variable to determine the delay between image rotations (in miliseconds) var slidedelay=3000 ////Do not edit pass this line//////////////// var ie=document.all var dom=document.getElementById for (i=0;i<variableslide.length;i++){ var cacheimage=new Image() cacheimage.src=variableslide[i][0] } var currentslide=0 function rotateimages(){ contentcontainer='<center>' if (variableslide[currentslide][1]!="") contentcontainer+='<a href="'+variableslide[currentslide][1]+'">' contentcontainer+='<img src="'+variableslide[currentslide][0]+'" border="0" vspace="3">' if (variableslide[currentslide][1]!="") contentcontainer+='</a>' contentcontainer+='</center>' if (variableslide[currentslide][2]!="") contentcontainer+=variableslide[currentslide][2] if (document.layers){ crossrotateobj.document.write(contentcontainer) crossrotateobj.document.close() } else if (ie||dom) crossrotateobj.innerHTML=contentcontainer if (currentslide==variableslide.length-1) currentslide=0 else currentslide++ setTimeout("rotateimages()",slidedelay) } if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>') function start_slider(){ crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub if (document.layers) document.slidensmain.visibility="show" rotateimages() } if (ie||dom) start_slider() else if (document.layers) window.onload=start_slider I have taken out the credit, as I have changed it a bit, but will reinstate it later on. All I really need to know is how to define it in the XHTML maybe. Can anyone help? Pretty pretty please help me with this I am running out of time and pulling my hair out with this whole thing. Thanks a million in advance! Rhonda <!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> function numberGuess() { stringVar=prompt("Enter your guess number"); while (stringVar<999) { } } </script> <script> function enterNames() { stringVar=prompt("Enter name"); } </script> <script> function enterProducts() { stringVar=prompt("Enter product name"); return } </script> </head> <body> <p> </p> <h1>WDV221 Intro Javascript</h1> <h3 align="center">Javascript Loops</h3> <p>Topics: loops, for loops, while loops, sentinels!</p> <p>Place all script code on this page.</p> <p>1. Create a function that will ask you for a number until you enter 999 which will end the loop. You do not need to display the number. </p> <p>2. Create a function that will ask you for a name until you tell the function that you do not have any more names. After you enter each name it will ask you if you have more names to enter. If you enter yes the process will continue. Display each name at the end of the following sentence.</p> <p>The name you entered is: </p> <p>3. Create a runtime script that will use a prompt( ) to accept how many products will be displayed. Use a for loop to display "Product Name" and the product number as a <p> element.</p> <p><strong>Example output:</strong></p> <p>Product Name 1</p> <p>Product Name 2</p> <p>...</p> <p>4. Create a runtime script that will use a nested for loop to create a table with 3 rows and 5 cells. Place the same number or a letter in each cell. </p> <p>Hint: Write a table in HTML. Do a row first then do multiple rows. </p> <p>5. Create a function called totalSales( ) that will ask the user to enter an amount until you enter "done". Add those amounts together and display them in an alert when the user is done entering amounts..</p> <p>Have fun!!</p> </body> </html> new to JavaScript, simple question... question: how do i determine an output from a prompt to be bold? e.g. a user enters "hello" and the output printed from the prompt becomes bold one=parseFloat(prompt('enter number',0.bold)); Hi, I'm trying to get my head around JS, but not too successfully yet. My objective is probably simple (but not to me ): to have a form where visitors enter 12 separate digits (ideally in minutes & hours, but am happy to use decimals), and the average of these (to two decimal points) is returned as document.write is it? - along with other text, to make a complete & coherent sentence, including the average of the 12 numbers. Does anyone have any code convenient that could do this? Thanks, LJ I have a vendor delivered java script code that I am currently customizing. The original code involves a user when selects a "check box" option value , a small function is called titled "VerifyAcctType". Currently when a user selects the check box some values are defaulted into the form. Now to this function code below i have to add logic when user selects the same check box option FIRST a small pop up window should appear which lists two radio buttons"I Agree to terms" and "I do not agree to terms" options , user need to select one of the options in the pop up to proceed. If the user agrees to terms then the control should go back to the "VerifyAcctType" function and proceed with remaining steps like before else if the user selects "I do not agree" the logic should not proceed further in "VerifyAcctType" function. Here is the current code tied to VerifyAcctType function ============================================== function VerifyAcctType(win,type) { var AcctType var ThisWindow var ThisForm if (win == "ADD") { ThisWindow = AddAccountWind ThisForm = AddAccountWind.document.addform } else if (win == "CHG") { ThisWindow = ChangeAccountWind ThisForm = ChangeAccountWind.document.chgform } if (type == "P") { <<I NEED NEW CODE HERE FOR THE POPUP>> Maccttype = type ThisForm.description.value = "My Company" ThisForm.comp_id.value = "1234567" ThisForm.comp_id.disabled = true } else { Maccttype = type ThisForm.description.value = "" ThisForm.comp_id.value = "" ThisForm.comp_id.disabled = false } } I am a java script beginner , any help is appreciated. 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! I tried to write the variable my_var into a text file but it only shows null after executing the code. Can anybody help pls?? Below is my code <html> <head> <script language="javascript"> var my_var function WriteToFile() { my_var = 123; document.write(<?php $file="file.txt"; $fh = fopen($file, 'w') or die("can't open file"); ?>; document.write(<?php $stringData = my_var ?>; document.write(<?php fwrite($fh, $stringData); ?>; document.write(<?php fclose($fh); ?>; } </script> </head> <body onLoad="WriteToFile();"> <p>Hello World</p> </body> </html> Hello everyone, i desperatly need a script for my website but am totally stuck, I hope someone can help On my website i want a search box. I want it so that if a use types in one of my predetermined search terms then they would be sent to a predeterimed page in my own website. For example: I have a group of 5 keywords - nokia, mobile, vodafone, cellphone, iphone. If a user types any of those keywords into my search box then xxxxx.com/mobilephones.htm will be loaded up I have another set of 5 keywords - cat, dog, rabbit, mouse, snake. If a user types any of those into the search box then they are directed to xxxxx.com/animals.htm and so on ... So as you can see, its not a 'normal' search engine I will be creating new pages and will need to add the chosen keywords for it as time goes on etc Nearly everywhere i look for something to help me all I can find are standard search engine scripts which are no good as they display search results instead of directing to specific urls depending on the keywords entered I would also need to 'capture' what search terms are being entered so that I can build some user statistics I understand html and javacript to an intermediate level Can anyone help / provide a script that I could use? Although Im a student Im willing to pay some funds to anyone that can do this for me Many thanks Terry Please see the below code. Is it possible for me to type in an order date in the browser & in the due date field, have it automatically populate a date 7 days greater than the date typed in the order date field? If so how? I have read I will probably need javascript to do this but have no clue where to start. Thanks for any help provided! <html> <head> <title> Update Database </title> </head> <body> <form method="post" action="add.php"> <b>First Name:</b> <br /> <input type="text" name="customer_fname" size="35" /><br /> <b>Last Name:</b> <br /> <input type="text" name="customer_lname" size="35" /><br /> <b>Location:</b> <br /> <input type="text" name="location" size="35" /><br /> <b>Order Date:</b> <br /> <input type="text" name="order_date" size="35" /><br /> <b>Due Date:</b> <br /> <input type="text" name="due_date" size="35" /><br /> <input type="submit" value="Submit" /> </form> </body> </html> I am still learning javascript so forgive me if this question is a bad one, I am making scripts for Greasemonkey for a website I am a part of. One of the developers recently commented out (in the source code) a feature that was available before. It is a Football MMORPG game and it used to show college players 40 times but over the past month he commented out the tag that held the script function. I want to know if i can either A) write a js code that can remove the comment tag in the source code or B) write a code that will just add another tag under that and have that js function that was commented out valid. I tried something but ended up just having that function pasted onto the page instead of having it put into the source to have it read by the rest of the data.. here is what im talking about <TABLE width=800 cellspacing=0> <tr> <td colspan=3 style="FONT-SIZE: 11pt"> <b>Hometown:</b>Fort Hunt, VA<br> <b>Height:</b>6-0<br> <b>Weight:</b>206<br> <!--b>40 Time:</b><if rs("team_id")>0 or bRated then><=formatnumber(rs("forty"),2)><br><end if --> i just want to see if there was any way to just delete the comment out of it so i can get this feature again is all. Any help would be awesome... and sorry for the long post I will be completely up front about this, its school work. At the end of a basic html class I missed several classes for family reasons and missed just about everything on Javascript. The book we used basically didnt cover anything over it, was all in class learning I missed. Anyone who could help would be so helpful. One function is partial, one is blank, thats what is supposed to be added/corrected to the following code Code: <html> <head> <script language="javascript" type="text/javascript"> function processScore() { var score = 0; if ( ...checked) {score = score + 1;} if (...checked) {score = score + 1;} document.answerForm.score.value = score; // Display the correct answers document.answerForm.answer1.value = " "; // put the correct value here document.answerForm.answer2.value = " "; // put the correct value here } //End of function processScore function clearForm() { // using the a javascript method clear all forms } </script> </head> <body style="font-family:tahoma; font-size:15px; line-height:200%; width:80%; margin-left:auto; margin-right:auto;"> <hr color="red" width="60%" size="5"> <form name="question1" id="question1"> 1. Which of the following is the document considered to be?<br/> <input type = "radio" name="choiceRB"> a. object<br /> <input type = "radio" name="choiceRB"> b. property<br /> <input type = "radio" name="choiceRB"> c. method<br /> </form> <hr color="green" width="60%" size="5"> <form name="question2" id="question2"> 2. Which method of the window can be used to display a message to the user?<br/> <input type = "radio" name="choiceRB"> a. display()<br /> <input type = "radio" name="choiceRB"> b. message()<br /> <input type = "radio" name="choiceRB"> c. alert()<br /> </form> <hr color="red" width="60%" size="5"> <input type="button" value="Grade the Quiz" onclick=?> <input type="button" value="Start Over" onclick=?> <form name="answerForm" id="answerForm"> <p><strong>Correct Answers:</strong><br/></p> Question 1: <input type="text" name="answer1" size="1"><br /> Question 2: <input type="text" name="answer2" size="1"><br /> <p>You scored <input type="text" name="score" size = "1"> out of 2</p> </form> <br /> </body> </html> thnx in advance to anyone who can help |