JavaScript - Suming Two Forms Result
Can any one help me out please, i have two forms result and i need a function to sum and display the two forms result into one
<html> <HEAD> <SCRIPT LANGUAGE="JavaScript"> function sum() { var one = parseFloat(document.myform.cost.value) var two = parseFloat(document.myform.insurance.value) var prod = one * two document.myform.amount.value=custRound(prod,2); } function custRound(x,places) { return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places) } var Cost, GST, PST, Grand_Total; function tally() { Cost = 0; if (document.orderform.Item1.checked) { Cost = Cost + 26.15; } if (document.orderform.Item2.checked) { Cost = Cost + 26.10; } if (document.orderform.Item3.checked) { Cost = Cost + 26; } if (document.orderform.Item4.checked) { Cost = Cost + 26; } if (document.orderform.Item5.checked) { Cost = Cost + 26.44; } if (document.orderform.Item6.checked) { Cost = Cost + 26.01; } if (document.orderform.Item7.checked) { Cost = Cost + 26; } if (document.orderform.Item8.checked) { Cost = Cost + 26; } if (document.orderform.Item9.checked) { Cost = Cost + 25; } GST = (Cost * 0.07); PST = (Cost * 0.07); Cost = dollar(Cost); GST = dollar(GST); PST = dollar(PST); Grand_Total = parseFloat(Cost) + parseFloat(GST) + parseFloat(PST) ; Grand_Total = dollar(Grand_Total); document.orderform.Total.value = "$" + Cost; document.orderform.GST.value = "$" + GST; document.orderform.PST.value = "$" + PST; document.orderform.GrandTotal.value = "$" + Grand_Total; } function dollar (amount) { amount = parseInt(amount * 100); amount = parseFloat(amount/100); if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0)) { amount = amount + ".00" return amount; } if ( ((amount * 10) - Math.floor(amount * 10)) == 0) { amount = amount + "0"; return amount; } if ( ((amount * 100) - Math.floor(amount * 100)) == 0) { amount = amount; return amount; } return amount; } </SCRIPT> </HEAD> <BODY> <H1 ALIGN = CENTER> in</H1> <H2 ALIGN = CENTER> PLEASE GET A QUOTE</H2> <FORM NAME="myform"> <P><B>VALUE OF Vehicle:</B> <input type="text" name="cost" onClick="sum()"> <P><B>Type of Insurance</B> <select name="insurance"> <option value="1.175" selected>Comprehensive</option> <option value="1.00">Third party only </option> <option value="0.75">Third party and thift</option> </select> <BR><input type="button" value="Get Quote" onClick="sum()" name="button"> <P>YOUR QUOTE </P> <input type="text" onClick="sum()" name="amount"> </FORM> </CENTER> <form method="post" name="orderform" action="mailto:ioduwa@yahoo.com" enctype="text/plain""> <table border="0"> <tr><td colspan="4"> <p><input type="checkbox" name="Item1" value="Item1_chosen" onclick="tally()"> Item One <p><input type="checkbox" name="Item2" value="Item2_chosen" onclick="tally()"> Item Two <p><input type="checkbox" name="Item3" value="Item3_chosen" onclick="tally()"> Item Three <p><input type="checkbox" name="Item4" value="Item4_chosen" onclick="tally()"> Item Four <p><input type="checkbox" name="Item5" value="Item5_chosen" onclick="tally()"> Item Five <p><input type="checkbox" name="Item6" value="Item6_chosen" onclick="tally()"> Item Six <p><input type="checkbox" name="Item7" value="Item7_chosen" onclick="tally()"> Item Seven <p><input type="checkbox" name="Item8" value="Item8_chosen" onclick="tally()"> Item Eight <p><input type="checkbox" name="Item9" value="Item9_chosen" onclick="tally()"> Item Nine </td></tr> <tr> <td> Total <input type="text" name="Total" value="$0" size="7"></td> <td> PST (7%) <input type="text" name="PST" value="$0" size="6"></td> <td colspan="2"> GST (7%) <input type="text" name="GST" value="$0" size="6"></td> </tr> <tr> <td> Grand Total <input type="text" name="GrandTotal" value="$0" size="8"></td> </tr> <tr> <td>Company Name:</td> <td colspan="3"><input type="Text" name="Company" size="35" maxlength="40"></td> </tr> <tr> <td>Contact Name:</td> <td colspan="3">First <input type="Text" name="FirstName" size="15" maxlength="20"> Last <input type="Text" name="LastName" size="15" maxlength="20"></td> </tr> <tr> <td>Address</td> <td><input type="Text" name="Street" size="20" maxlength="40"></td> </tr> <tr> <td>City</td> <td><input type="Text" name="City" size="20" maxlength="20"> </td> <td>Province/State:</td> <td><input type="Text" name="Province" size="20" maxlength="40"></td> </tr> <tr> <td>Country:</td> <td><input type="Text" name="Country" size="20" maxlength="20"></td> <td>Code:</td> <td><input type="Text" name="Code" size="9" maxlength="10"></td> </tr> <tr> <td>Phone:</td> <td><input type="Text" name="Area" size="3" maxlength="5"> <input type="Text" name="Phone" size="8" maxlength="10"></td> <td>Fax:</td> <td><input type="Text" name="AreaFax" size="3" maxlength="5"> <input type="Text" name="Fax" size="8" maxlength="10"></td> </tr> <tr> <td>Email Address:</td> <td colspan=2><input type="Text" name="Email" size="30" maxlength="30"></td> </tr> <tr><td colspan="4" height="3"><hr></td></tr> <tr><td colspan="2" align="center"><input type="Submit" value="Send Order"></td> <td colspan="2" align="center"><input type="RESET" value="Reset Order"></td></tr> </table> </form> </html> Similar TutorialsI'm using the autofill forms plugin for firefox which can be found he https://addons.mozilla.org/en-US/firefox/addon/4775 I use it to automatically fill various web forms, duh. But I would like certain values to be chosend randomly from a list I create. I contacted the developer and he said the add on probably does not need a new feature because there is a 'dynamic tags' function to fill certain forms with dynamic values (e.g. the current time or date). He has given over the project to another developer and told me I probably would find a solution in a good javascript programming forum. So here I am! Can anyone help me with this? Basically, I just need a javascript code which chooses on item from an array randomly, I guess? I'm not a programmer myself, so any help would be greatly (!) appreciated. Thanks a lot in advance for any further guidance! Note: Here are sample dynamic tags from the plugin: <datetime> new Date().toLocaleString() <useragent> navigator.userAgent <langcode> navigator.language <resolution> screen.width+'x'+screen.height <clipboard> this.getClipboardText() I will tell you now that I am not a javascript programmer and this is a very basic question. Please don't flame. I have been writing a web site and have found 2 functions that work and do what I want them to do, but I want to combine them. The first function will grab the window size.(it actually prints it out to the screen and I know how to get that to stop by taking out the last 2 lines) What I want to do with the results from the function alertSize() is exactly what the function res() does though. I want it to take the window size and jump to the appropriate web directory. What I don't know is if I can write that all as one function or if I have to pass the results of function alertSize() to function res(). Or how to do it for that matter, I don't even know what this is called in programming lingo. I am not asking for an answer here I would just like someone to point me in the right direction that I may learn a little more about what it is I want to do so I can get this to work. Giving me a search term would be a BIG help. Here is the first function. Code: // <script language="JavaScript"> //--> function alertSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } window.alert( 'width = ' + myWidth ); window.alert( 'height = ' + myHeight ); } // </script> //--> and the second function. Code: // <script language="JavaScript"> //--> function res() { alert('Screen Resolution Is '+screen.width+' by '+screen.height); } if ((screen.width>=1280) && (screen.height>=1024)) { window.location="/12/index.html"; } else if ((screen.width>=1024) && (screen.height>=768)) { window.location="/10/index.html"; } else if ((screen.width>=800) && (screen.height>=600)) { window.location="lowres1.html"; } else if ((screen.width>=640) && (screen.height>=480)) { window.location="lowres2.html"; } else { window.location="lowres3.html"; } // </script> //--> Hi there, i have a dynamic form that is populated via a sql query (WHERE $AVAILABLE_PRODUCT > 0) hence the javascript that is called onchange has dynamic field names. i used numbers. the for loop works fine: Code: var numberOfFields = document.order_form.elements.length; for (var i=1; i<numberOfFields-3; i=i+4) { if (document.order_form.elements[i].value > document.order_form[i+3].value) { alert(document.order_form.elements[i].value + ' > ' + document.order_form[i+3].value); } .... } Alert Box shows: 3 > 17 or similar (where 17 is the number of items on stock, and three the number of items ordered.) all other calculations with that form work fine. any idea? Hello ! I am trying to create an auto suggest drop down. I have some ASP and Javascript code that I am using as an Autosuggest. Trouble is, the result displays on the main page, not under the text box like a drop down menu. I need help in getting the results to display correctly underneath the textbox. I have trawlled the internet and have loads and loads of code samples but I cant see the wood for the trees and I am really struggling with editing this code so that it displays correctly. clienthint.asp Code: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <html> <head> <script src="clienthint.js"></script> </head> <body> <% 'this displays the value of the textbox after the form is submitted If trim(Request("txt1")) <> "" Then Response.Write "You entered:" Response.Write "<b>" & Request("txt1") & "</b><br /><br />" End If %> <form name="form1" action="clienthint.asp" method="post"> Enter Word: <input type="text" name="txt1" id="txt1" onKeyUp="showHint(this.value,'txt1','form1',true)"> <input type="submit" name="submit" value="submit"> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html> clienthint.js Code: var xmlHttp function showHint(str, box, thisForm, autoSubmit) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="gethint.asp"; url=url+"?q="+str; url=url+"&b="+box; url=url+"&f="+thisForm; url=url+"&a="+autoSubmit; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlHttp.responseText; } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } //this function allows for Clickable suggestions function setTextBox(thisText,thisBox,thisForm,autoSubmit){ document.getElementById(thisBox).value = thisText //this autoSubmits the form after a suggestion is clicked - it is not working :( //if(autoSubmit=='true'){ // alert(thisForm); // document.getElementById(thisForm).submit(); //} } gethint.asp Code: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% response.expires=-1 Dim rsWords Dim rsWords_numRows Dim q Dim b Dim hint q=ucase(request.querystring("q")) b=(request.querystring("b")) f=(request.querystring("f")) a=(request.querystring("a")) hint="" Set rsWords = Server.CreateObject("ADODB.Recordset") rsWords.ActiveConnection = "Provider=SQLOLEDB; Data Source=JAGUAR\SQLEXPRESS; Initial Catalog=67625252; User ID=SFSDFSDF; Password=KJHSDHFJHDF" rsWords.Source = "SELECT * FROM Rmatable WHERE (RMA_ID LIKE'" + q + "%') ORDER BY RMA_ID" rsWords.CursorType = 2 rsWords.CursorLocation = 2 rsWords.LockType = 3 rsWords.Open() rsWords_numRows = 0 If Not rsWords.EOF Then Do While Not rsWords.EOF If trim(hint) = "" Then hint = "<a href=""javascript:setTextBox('" & rsWords("RMA_ID") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("RMA_ID") & "</a>" Else hint = hint & " , <a href=""javascript:setTextBox('" & rsWords("RMA_ID") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("RMA_ID") & "</a>" End If rsWords.MoveNext() Loop End If if trim(hint)="" then response.write("no suggestion") else response.write(hint) end if rsWords.Close() Set rsWords = Nothing %> Hey Forum, I have this little script working great when all if's are seperated. what i need is to have the script read if one of these fields has a value then result=true. as you see the script now i have this seperated in many different if's for all three text fields. I need to put all text fields like they were one, thanks Code: function ValidateLink(Form) { var result = true; if (formMyLocations.cellAddress.value.length == 0) { alert('Cell address is empty on the locations page'); result = false; } if (formMyLocations.homeAddress.value.length == 0) { alert('Home address is empty on the locations page'); result = false; } if (formMyLocations.carAddress.value.length == 0) { alert('Car address is empty on the locations page'); result = false; } return result; } Finally got my favorite system to work but there is 1 little detail left... When an item is in the favorites, the php file echoes: "Already Favorited!" how can I get that response? I have no experience with js whatsoever.. first time I used it. (obvious since I use code that i found on the tubes and modded it) This is my code: PHP Code: /* ---------------------------- */ /* XMLHTTPRequest Enable */ /* ---------------------------- */ function createObject() { var request_type; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ request_type = new ActiveXObject("Microsoft.XMLHTTP"); }else{ request_type = new XMLHttpRequest(); } return request_type; } var http = createObject(); var nocache = 0; function insert() { // Optional: Show a waiting message in the layer with ID login_response document.getElementById('insert_response').innerHTML = "Adding..." // Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding. var user_id= encodeURI(document.getElementById('user_id').value); var item_id = encodeURI(document.getElementById('item_id').value); var cat_id = encodeURI(document.getElementById('cat_id').value); // Set te random number to add to URL request nocache = Math.floor(Math.random()); // Pass the login variables like URL variable http.open('get', 'http://animekyun.com/scripts/favorite.php?user_id='+user_id+'&item_id=' +item_id+'&cat_id=' +cat_id); http.onreadystatechange = insertReply; http.send(null); } function insertReply() { if(http.readyState == 4){ var response = http.responseText; document.getElementById('insert_response').innerHTML = 'Favorited'+response; } } Apparently this http.responseText is not working propperly since it's not returning anything Good day to you all, I'm working on a form which would display the result in the same div that the form is. Here is my code so far: PHP Code: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <textarea name="html"></textarea><br /> <input type="submit" onclick="load('<?php echo $_SERVER['PHP_SELF']; ?>','page');"/><br /> </form> Preview:<br /> <?php if(isset($_POST['html'])) echo stripslashes($_POST['html']); ?> <script type="text/javascript"> function ahah(url, target) { document.getElementById(target).innerHTML = ' Fetching data...'; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req != undefined) { req.onreadystatechange = function() {ahahDone(url, target);}; req.open("GET", url, true); req.send(""); } } function ahahDone(url, target) { if (req.readyState == 4) { // only if req is "loaded" if (req.status == 200) { // only if "OK" document.getElementById(target).innerHTML = req.responseText; } else { document.getElementById(target).innerHTML=" Error:\n"+ req.status + "\n" +req.statusText; } } } function load(name, div) { ahah(name,div); return false; } </script> My problem is when I click on the button , the text in my text area don't show. Can somebody help me. Thanks! Can anyonle pls explain me why the return function is not returning the result as intended? I appreciate you help OUTPUT ====== Student : Doe,John eMail : johndoe@gmail.com Course ID : COIN-070B.01 -------------------------------- function task() { var title = ["Assignment1", "Assignment2", "Assignment3", "Assignment4", "Assignment5", "Mid Term", "Finals"]; var points = [30, 30, 28, 27, 29, 41, 45]; for (var i = 0; i < points.length; i++) { titlePoints += title[i] + (" : " + points[i] + "\n"); } return titlePoints; } Code: <head> <title>Variable - Examples 1</title> <script type="text/javascript"> function Student(firstName, lastName, email,courseID){ this.firstName = firstName; this.lastName = lastName; this.email = email; this.courseID = courseID; this.assignments = task; } Student.prototype = { constructor : Student, toString : studentInfo }; function task(){ var title = ["Assignment1","Assignment2","Assignment3","Assignment4","Assignment5","Mid Term", "Finals"] var points = [30, 30, 28, 27, 29,41,45]; var titlePoints = ""; for (var i=0; i < points.length; i++){ titlePoints += title[i] + " : " + points[i] + "\n"; } return titlePoints; } function studentInfo(){ return "Student : " + this.lastName + "," + this.firstName + "<br>"+ "eMail : " + this.email + "<br>" + "Course ID : " + this.courseID + "<br>" + "--------------------------------" + "<br>" + this.assignments; } var student = new Student("John", "Doe", "johndoe@gmail.com","COIN-070B.01"); </script> </head> <body> <script type="text/javascript"> document.writeln(student.toString()); </script> </body> </html> I wrote quiz using HTML and JavaScrip. Score is accumulated in a variable called myScore. Now I want to email the result of myScore to an email address. How do I go about doing this? I don't want to use the mailto: command since that require that user actually press the send command to send the email. I want this done automatically after user finishes the quiz. Please explain all replied in details since I am new to JavaScript and still learning. When I hit the submit button, the result are display on a new page. how do I force it to stay on the same page, here's my code. Code: <HTML> <HEAD> <TITLE>Test Input</TITLE> <script type="text/javascript"> function addtext() { var newtext = document.myform.inputbox.value; document.writeln(newtext); } </script> </HEAD> <BODY> <FORM NAME="myform">Enter something in the box: <BR> <INPUT TYPE="text" NAME="inputbox" VALUE=""> <INPUT TYPE="button" NAME="button" Value="Check" onClick="addtext()"> </FORM> </BODY> </HTML> any comments or suggestions would be greatly appreciated. Hello all, I am new to these forms, and new to Javascript as well. I have gone through some lessons, and have been trying to write a simple script on my own. Here is what I am trying to do: I am calculating a volume, and want to display the result of that calculation. I then want to take the result and multiply it by 2 and display that as well. Here is what I have so far: Code: function volume (l, w, h) { return l * w * h; } console.log("Volume = " + volume (2, 2, 2)); So far so good... but I cant figure out how to then take that result that was displayed in the console and save it as a variable (if that would be the correct way to do it) so that I can modify the result by 2. I have tried several things with no luck. How can I save the result of a function or pass it to another function? Thanks in advance! I am trying to set up a small legend type html. What I am trying to accomplish is to give the user a description depending on the abbv they pick from the drop down. This all works fine, however I now want to improve this to actually give them a link to a site if they want to research the description further. I can get it to work if I do document.write but I want the link to go into the text box. I also thought about making a button to the side that would probably need some sort of function to call each url. That may come down the road but the simpler way would be nice. I have a js called abbs there is actually two ways to do the drop downs but I am only concerned with adding links to the top one. On the CCVT option I have added a link but the only way I can get it to work is through document.write. Here is my JS code: Code: function findMEAN(){ var abb = document.listNAME.abbWRD.value; if (abb == "AEP"){ abbs = ("American Electric Power") ;} else if (abb == "A"){ abbs = ("AMP") ;} else if (abb == "AC"){ abbs = ("ALTERNATING CURRENT") ;} else if (abb == "ACI"){ abbs = ("AMERICAN CONCRETE INSTITUTE") ;} else if (abb == "ACB"){ abbs = ("AIR CIRCUIT BREAKER") ;} else if (abb == "AISC"){ abbs = ("AMERICAN INSTITUTE OF STEEL CONSTRUCTION") ;} else if (abb == "ANSI"){ abbs = ("AMERICAN NATIONAL STANDARDS INSTITUTE") ;} else if (abb == "ARO"){ abbs = ("AUTOMATIC RECLOSING OPERATION") ;} else if (abb == "ASCE"){ abbs = ("AMERICAN SOCIETY OF CIVIL ENGINEERS") ;} else if (abb == "ASTM"){ abbs = ("AMERICAN SOCIETY FOR TESTING AND MATERIAL") ;} else if (abb == "AUX"){ abbs = ("AUXILUARY") ;} else if (abb == "AWG"){ abbs = ("AMERICAN WIRE GAUGE") ;} else if (abb == "BCT"){ abbs = ("BUSHING CURRENT TRANSFORMER") ;} else if (abb == "BIL"){ abbs = ("BASIC INSULATION LEVEL") ;} else if (abb == "BOM"){ abbs = ("BILL OF MATERIAL") ;} else if (abb == "BPD"){ abbs = ("BUSHING POTENTIOAL DEVICE") ;} else if (abb == "BPLC"){ abbs = ("BROADBAND POWER LINE CARRIER") ;} else if (abb == "BT"){ abbs = ("BUS TIE") ;} else if (abb == "CAB"){ abbs = ("CABLE") ;} else if (abb == "CAT#"){ abbs = ("CATALOG NUMBER") ;} else if (abb == "CB"){ abbs = ("CIRCUIT BREAKER") ;} else if (abb == "CCVT"){ abbs = ("COUPLING CAPACITOR VOLTAGE TRANSFORMER") ; abbslnk = "<p>Link: " + abbs.link("http://www.abb.com/product/db0003db002618/c12573e7003302adc1256ffd001d1256.aspx") + "</p>";} else if (abb == "CS"){ abbs = ("CIRCUIT SWITCHER") ;} else if (abb == "CT"){ abbs = ("CURRENT TRANSFORMER") ;} else if (abb == "CVT"){ abbs = ("CAPACITOR VOLTAGE TRANSFORMER") ;} else if (abb == "DC"){ abbs = ("DIRECT CURRENT") ;} else if (abb == "DEB"){ abbs = ("DOUBLE END BREAK") ;} else if (abb == "DMS"){ abbs = ("DATA MANAGEMENT SYSTEM/DIGITAL METERING SYSTEM") ;} else if (abb == "FDN"){ abbs = ("FOUNDATION") ;} else if (abb == "FMP"){ abbs = ("FIELD MARKED PRINT") ;} else if (abb == "GIS"){ abbs = ("GAS INSULATED SYSTEM") ;} else if (abb == "GND,GRDG"){ abbs = ("GROUND(ING)") ;} else if (abb == "GOAB"){ abbs = ("GAS OPREATED AIR BREAK") ;} else if (abb == "GOS"){ abbs = ("GANG OPREATED SWITCH") ;} else if (abb == "IFC"){ abbs = ("ISSUE FOR CONSTRUCTION") ;} else if (abb == "KA"){ abbs = ("KILO AMP") ;} else if (abb == "KCM"){ abbs = ("KILO(1000) CIRCULAR-MILS") ;} else if (abb == "KV"){ abbs = ("KILOVOLT") ;} else if (abb == "KVAR"){ abbs = ("KILOVOLT-AMPERES REACTIVE") ;} else if (abb == "LTC"){ abbs = ("LOAD TAP CHANGER") ;} else if (abb == "MLSE"){ abbs = ("MOST LIMITING SIGNIFICANT ELEMENT") ;} else if (abb == "MOAB"){ abbs = ("MOTOR OPERATED AIR BREAK") ;} else if (abb == "MOD"){ abbs = ("MOTOR OPERATED DISCONNECT") ;} else if (abb == "MR"){ abbs = ("MATERIAL REQUEST") ;} else if (abb == "MVAR"){ abbs = ("MEGAVOLT AMPERE REACTIVE") ;} else if (abb == "N.C."){ abbs = ("NORMALLY CLOSED") ;} else if (abb == "N.O."){ abbs = ("NORMALLY OPEN") ;} else if (abb == "NEMA"){ abbs = ("NATIONAL ELECTRICAL MANUFACTURER\'S ASSOCIATION") ;} else if (abb == "OCB"){ abbs = ("OIL CIRCUIT BREAKER") ;} else if (abb == "OEC"){ abbs = ("OUTSOURCED ENGINEERING COMPANY") ;} else if (abb == "OLD"){ abbs = ("ONE LINE DIAGRAM") ;} else if (abb == "OSHA"){ abbs = ("OCCUPATIONAL SAFETY AND HEALTH ADMINISTRATION") ;} else if (abb == "P&C"){ abbs = ("PROTECTION & CONTROL") ;} else if (abb == "PCIS"){ abbs = ("PROTECTION AND CONTROL INFORMATION SYSTEM") ;} else if (abb == "PCSS"){ abbs = ("PROTECTION & CONTROL SUPPORT SERVICES") ;} else if (abb == "PED"){ abbs = ("PROTECTION EXECUTION DOCUMENT") ;} else if (abb == "POP"){ abbs = ("PHASE OVER PHASE") ;} else if (abb == "PRA"){ abbs = ("PROJECT ROUTING & APPROVAL") ;} else if (abb == "PT"){ abbs = ("POTENTIAL TRANSFORMER") ;} else if (abb == "RIM"){ abbs = ("RELAY INSTRUMENTATION & METERING") ;} else if (abb == "RMS"){ abbs = ("ROOT MEAN SQUARE") ;} else if (abb == "RPA"){ abbs = ("R(TU) POINT ASSIGNMENT") ;} else if (abb == "RTU"){ abbs = ("REMOTE TERMINAL UNIT") ;} else if (abb == "S/N"){ abbs = ("SERIAL NUMBER") ;} else if (abb == "SA"){ abbs = ("SURGE ARRESTOR") ;} else if (abb == "SCADA"){ abbs = ("SUPERVISORY CONTROL AND DATA ACQUISITION") ;} else if (abb == "XF"){ abbs = ("TRANSFORMER") ;} else if (abb == "WD"){ abbs = ("WIRING DIAGRAM") ;} else if (abb == "VCB"){ abbs = ("VACUUM CIRCUIT BREAKER") ;} else if (abb == "V"){ abbs = ("VOLT") ;} else if (abb == "TCR"){ abbs = ("TRANSMISSION CONSTRUCTION REPRESENTATIVE") ;} else if (abb == "SW"){ abbs = ("SWITCH") ;} else if (abb == "SOW"){ abbs = ("SCOPE OF WORK") ;} else if (abb == "SESS"){ abbs = ("STATION ENGINEERING SUPPORT SERVICES") ;} { var result=document.getElementById("resultbox"); result.value = abbslnk } Here is my HTML code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>ACRONYMS</title> <script type= "text/javascript" src="abbs.js"> </script> <style type="text/css" media="Screen"> fieldset { border: 5px solid #555555; padding: 20px; width:350px; word-wrap: normal; } </style> </head> <body> <fieldset style="width:410px; height: 250px"> <h2>DESCRIPTION BY ABBV</h2> <form name = "listNAME"> <select name="abbWRD"> <option value=A>A</option> <option value=AC>AC</option> <option value=ACB>ACB</option> <option value=ACI>ACI</option> <option value=AEP>AEP</option> <option value=AISC>AISC</option> <option value=ANSI>ANSI</option> <option value=ARO>ARO</option> <option value=ASCE>ASCE</option> <option value=ASTM>ASTM</option> <option value=AUX>AUX</option> <option value=AWG>AWG</option> <option value=BCT>BCT</option> <option value=BIL>BIL</option> <option value=BOM>BOM</option> <option value=BPD>BPD</option> <option value=BPLC>BPLC</option> <option value=BT>BT</option> <option value=CAB>CAB</option> <option value=CAT#>CAT#</option> <option value=CB>CB</option> <option value=CCVT>CCVT</option> <option value=CS>CS</option> <option value=CT>CT</option> <option value=CVT>CVT</option> <option value=DC>DC</option> <option value=DEB>DEB</option> <option value=DMS>DMS</option> <option value=FDN>FDN</option> <option value=FMP>FMP</option> <option value=GIS>GIS</option> <option value=GND,GRDG>GND,GRDG</option> <option value=GOAB>GOAB</option> <option value=GOS>GOS</option> <option value=IFC>IFC</option> <option value=KA>KA</option> <option value=KCM>KCM</option> <option value=KV>KV</option> <option value=KVAR>KVAR</option> <option value=LTC>LTC</option> <option value=MLSE>MLSE</option> <option value=MOAB>MOAB</option> <option value=MOD>MOD</option> <option value=MR>MR</option> <option value=MVAR>MVAR</option> <option value=N.C.>N.C.</option> <option value=N.O.>N.O.</option> <option value=NEMA>NEMA</option> <option value=OCB>OCB</option> <option value=OEC>OEC</option> <option value=OLD>OLD</option> <option value=OSHA>OSHA</option> <option value=P&C>P&C</option> <option value=PCIS>PCIS</option> <option value=PCSS>PCSS</option> <option value=PED>PED</option> <option value=POP>POP</option> <option value=PRA>PRA</option> <option value=PT>PT</option> <option value=RIM>RIM</option> <option value=RMS>RMS</option> <option value=RPA>RPA</option> <option value=RTU>RTU</option> <option value=S/N>S/N</option> <option value=SA>SA</option> <option value=SCADA>SCADA</option> <option value=SESS>SESS</option> <option value=SOW>SOW</option> <option value=SW>SW</option> <option value=TCR>TCR</option> <option value=V>V</option> <option value=VCB>VCB</option> <option value=WD>WD</option> <option value=XF>XF</option> </select> </form><br> <input value="Click for Description" onclick="findMEAN()" type="button"> </br></br> <input type="text" name="myresultbox" id="resultbox" style="width:400px; height:75px;"> </fieldset><br> <fieldset style="width:350px; height: 250px"> <h2>ABBV BY DESCRIPTION</h2> <form name = "listDESC"> <select name="abbABB"> <option value=A>AMP</option> <option value=AC>ALTERNATING CURRENT</option> <option value=ACB>AIR CIRCUIT BREAKER</option> <option value=ACI>AMERICAN CONCRETE INSTITUTE</option> <option value=AEP>AMERICAN ELECTRICAL POWER</option> <option value=AISC>AMERICAN INSTITUTE OF STEEL CONSTRUCTION</option> <option value=ANSI>AMERICAN NATIONAL STANDARDS INSTITUTE</option> <option value=ARO>AUTOMATIC RECLOSING OPERATION</option> <option value=ASCE>AMERICAN SOCIETY OF CIVIL ENGINEERS</option> <option value=ASTM>AMERICAN SOCIETY FOR TESTING AND MATERIAL</option> <option value=AUX>AUXILUARY</option> <option value=AWG>AMERICAN WIRE GAUGE</option> <option value=BCT>BUSHING CURRENT TRANSFORMER</option> <option value=BIL>BASIC INSULATION LEVEL</option> <option value=BOM>BILL OF MATERIAL</option> <option value=BPD>BUSHING POTENTIOAL DEVICE</option> <option value=BPLC>BROADBAND POWER LINE CARRIER</option> <option value=BT>BUS TIE</option> <option value=CAB>CABLE</option> <option value=CAT#>CATALOG NUMBER</option> <option value=CB>CIRCUIT BREAKER</option> <option value=CCVT>COUPLING CAPACITOR VOLTAGE TRANSFORMER</option> <option value=CS>CIRCUIT SWITCHER</option> <option value=CT>CURRENT TRANSFORMER</option> <option value=CVT>CAPACITOR VOLTAGE TRANSFORMER</option> <option value=DC>DIRECT CURRENT</option> <option value=DEB>DOUBLE END BREAK</option> <option value=DMS>DATA MANAGEMENT SYSTEM/DIGITAL METERING SYSTEM</option> <option value=FDN>FOUNDATION</option> <option value=FMP>FIELD MARKED PRINT</option> <option value=GIS>GAS INSULATED SYSTEM</option> <option value=GND,GRDG>GROUND(ING)</option> <option value=GOAB>GAS OPREATED AIR BREAK</option> <option value=GOS>GANG OPREATED SWITCH</option> <option value=IFC>ISSUE FOR CONSTRUCTION</option> <option value=KA>KILOAMP</option> <option value=KCM>KILO(1000) CIRCULAR-MILS</option> <option value=KV>KILOVOLT</option> <option value=KVAR>KILOVOLT-AMPERES REACTIVE</option> <option value=LTC>LOAD TAP CHANGER</option> <option value=MLSE>MOST LIMITING SIGNIFICANT ELEMENT</option> <option value=MOAB>MOTOR OPERATED AIR BREAK</option> <option value=MOD>MOTOR OPERATED DISCONNECT</option> <option value=MR>MATERIAL REQUEST</option> <option value=MVAR>MEGAVOLT-AMPERES REACTIVE</option> <option value=N.C.>NORMALLY CLOSED</option> <option value=N.O.>NORMALLY OPEN</option> <option value=NEMA>NATIONAL ELECTRICAL MANUFACTURER'S ASSOCIATION</option> <option value=OCB>OIL CIRCUIT BREAKER</option> <option value=OEC>OUTSOURCED ENGINEERING COMPANY</option> <option value=OLD>ONE LINE DIAGRAM</option> <option value=OSHA>OCCUPATIONAL SAFETY AND HEALTH ADMINISTRATION</option> <option value=P&C>PROTECTION AND CONTROL</option> <option value=PCIS>PROTECTION AND CONTROL INFORMATION SYSTEM</option> <option value=PCSS>PROTECTION AND CONTROL SUPPORT SERVICES</option> <option value=PED>PROTECTION EXECUTION DOCUMENT</option> <option value=POP>PHASE OVER PHASE</option> <option value=PRA>PROJECT ROUTING AND APPROVAL</option> <option value=PT>POTENTIAL TRANSFORMER</option> <option value=RIM>RELAY INSTRUMENTATION AND METERING</option> <option value=RMS>ROOT MEAN SQUARE</option> <option value=RPA>R(TU) POINT ASSIGNMENT</option> <option value=RTU>REMOTE TERMINAL UNIT</option> <option value=S/N>SERIAL NUMBER</option> <option value=SA>SURGE ARRESTOR</option> <option value=SCADA>SUPERVISORY CONTROL AND DATA ACQUISITION</option> <option value=SESS>STATION ENGINEERING SUPPORT SERVICES</option> <option value=SOW>SCOPE OF WORK</option> <option value=SW>SWITCH</option> <option value=TCR>TRANSMISSION CONSTRUCTION REPRESENTATIVE</option> <option value=V>VOLT</option> <option value=VCB>VACUUM CIRCUIT BREAKER</option> <option value=WD>WIRING DIAGRAM</option> <option value=XF>TRANSFORMER</option> </select> </form><br> <input value="Click for ABBV" onclick="findABB()" type="button"> </br></br> <input type="text" name="myresultbox2" id="resultbox2" style="width:200px; height:75px;"> </fieldset><br> </body> </html> So in summary everything is working just want to make the result in the result box be able to be clinked to a specific link assigned. Thank you in advance. Hello, this is a homework project which kind of works but isn't perfect. My tutor said the result must be an alert but I ended up with a document.write instead. He said it was fine but I'd like to know how to make it alert the result if anyone can help. FWIW I tried making the contents of the for loop into a variable without success. Code: <form action="javascript: displaymessage();" method="get" /> <p>Please enter a word: <input id="user_word" name="user_wrd" type="text" /> <input type="submit" value="Submit" /> </p> <script type="text/javascript"> function displaymessage() { /*Set a variable for the user's word*/ var word_forward; /*Get the user's word from the form above and put it into the new variable*/ word_forward = document.getElementById("user_word").value; /*Write the user's word from the variable to the page*/ document.write('<p>The word is: ' + word_forward + '.</p>'); /*Calculate the length of the user's word*/ var word_length=word_forward.length; /*Write the length of the user's word to the page*/ document.write('<p>The word length is: ' + word_length + ' characters.</p>'); /*Subtract 1 from word length variable to allow for character index numbers starting from zero*/ word_length2=(word_length-1); /*Set a variable for the character index number*/ var char_num; /*Write the first part of the result line*/ document.write('The word spelled backwards is: '); /*Begin character index number countdown loop: loop start value / loop end value / increment*/ for(char_num=word_length2; char_num>=0; char_num--) { /*Write word backwards using charAt*/ document.write(word_forward.charAt(char_num) + " "); } } </script> Hi guys, I'm new to the forum, and new to JavaScipt. Here's my problem. I create a form dynamically with Java Script dependin on certail actions a user choose. The end result is a form asking the user to confirm sending one or more SMS message via a mesage gateway outside of my system. Confirmation will then trigger a funtion with one or more statements like this: [CODE] document.frmSMS.action ="http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=User&password=Password&sender=Sender&SMSText=Friendly Reminder from Joe Bloggs Pty Ltd: You have an outstanding amount of R 4,534.00 that is 135 days ovedue. Please settle to as soon possible.&IsFlash=0&GSM=27826555959"; document.frmSMS.submit(); [ICODE] The target site then responds with either an error code (i.e. -10) or a reference number. The question is - How do I retrieve the error code?? Your assistance will be appreciated. NicOos <html> <head> <title></title> <script language="JavaScript"> <!-- function multiply() { // Get values from form var num1, num2; num1 = parseInt(document.calcForm.num1.value); num2 = parseInt(document.calcForm.num2.value); // Compute the product. var product = num1*num2*50; // Display product in form. document.calcForm.output.value = product; } //--> </script> </head> <body> <? if($_POST[comments]!=""){ mail("myemailaddress", $_POST[subject], "From Email: $_POST[youremail] $_POST[comments] "); echo " Thanks for your comment"; } ?> <h1 align="center">Price</h1> <form name="calcForm"> <p>Please Enter the dimensions</p> <p>Width: <input type="text" name="num1" size="10"></p> <p>Length: <input type="text" name="num2" size="10"></p> <input type="button" value="number" onClick="multiply()"> <hr /> <p>result; <input type="text" name="output" size="20" readonly></p> <p> <input type="submit" name="button" id="button" value="Finish" /> </p> </form> </body> </html> thank you
Good Day, I am very new to JavaScript and I am working on an assignment that is almost finished, but I have a problem getting the result to work. When I enter the two values and then hit submit, nothing is returned. I am guessing that either my code is incorrect or I have used the wrong ids maybe. Basically, the user enters 2 parameters (hourly wage and hours worked) and the first function turns the parameters into the gross pay (depends on if the hours are standard pay or if overtime is involved). The second function takes the gross pay and does the tax amounts for local, state and federal. Then it adds all taxes to give a total of tax amount paid. The input for the parameters is done by <input> tag. The return reslut is supposed to be just the number which is the total amount of taxes to be taken out. This all has to be done by <input> tags. Could someone look over the html and JS and help me find where the problem is at. The instructor said we could use ? : operator for determining the pay rates, but I found it easier to do if/else staements because I was not sure how you would script that. Any help would be great. Thanks HTML Code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Calculate Tax Amount</title> <link href="style.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="calculateGross.js"></script> <script type="text/javascript" src="calculateTax.js"></script> </head> <body> <table width="60%" border="0" cellpadding="0" cellspacing="2" align="center" class="view"> <tr> <td colspan="3" class="textview">Calculate the gross pay:</td> </tr> <tr> <td class="labeltext">Pay rate(dollars per hour)</td> <td>:</td> <td><input type="text" name="payrate" id="payrate" class="textval"></td> </tr> <tr> <td class="labeltext">Hours worked</td> <td>:</td> <td><input type="text" name="hours" id="hours" class="textval"></td> </tr> <tr> <td colspan="3" align="center"><input type="button" name="" value="Submit" onclick="return calculate(); "> </td> </tr> </table> <br> <br> <table width="60%" border="0" cellpadding="0" cellspacing="2" align="center" class="view"> <tr> <td colspan="3" class="textview">Total Tax Paid:</td> <tr> </tr> <td class="labeltext">Grand Total of Taxes</td> <td>:</td> <td><input type="text" name="total" id="totalTax" class="textval" disabled="disabled"></td> </tr> </table> </body> </html> First Function JS Code: function calculate() { var payRate = document.getElementById("payrate").value; var hoursWorked = document.getElementById("hours").value; var oTime; var oPay; var oHour; var grossPay; if(hoursWorked > 40) { oTime = Number ( hoursWorked ) - 40; oPay = Number ( ( payRate ) * 1.5 ) * oTime; oHour = Number ( hoursWorked )- Number ( oTime ); grossPay = Number ( payRate ) * Number ( oHour ) + Number ( oPay ); } else grossPay = Number ( hoursWorked ) * Number ( payRate ); } The second function JS Code: function calculateTax(gross) { var gross; var localTax; var localTaxBal; var stateTax; var stateTaxBal; var fedTax; var fedTaxBal; var totalTax; localTax = Number ( gross ) * 2/100; localTaxBal = Number ( gross ) - Number ( localTax ); stateTax = Number ( localTaxBal ) * 8/100; stateTaxBal = Number ( localTaxBal ) - Number ( stateTax ); fedTax = Number ( stateTaxBal ) * 31/100; fedTaxBal = Number ( stateTaxBal ) - Number ( FedTax ); totalTax = Number ( localTax.toFixed(2) ) + Number ( stateTax.toFixed(2) ) + Number ( fedTax.toFixed(2) ); return totalTax.toFixed(2); } |