JavaScript - How To Make A Reverse Output?
I'm pretty beginner at javascript, and I have this script for letter to phonetic:
Code: <script language="JavaScript"> function flip() { var result = flipString(document.f.original.value.toLowerCase()); document.f.flipped.value = result; } function flipString(aString) { var last = aString.length - 1; var result = new Array(aString.length) for (var i = last; i >= 0; --i) { var c = aString.charAt(i) var r = flipTable[c] result[i] = r != undefined ? r : c } return result.join('') } var flipTable = { a : 'aye ', b : 'bee ', c : 'sea ', d : 'dee ', e : 'eeh ', f : 'eff ', g : 'gee ', h : 'aych ', i : 'eye ', j : 'jay ', k : 'kay ', l : 'el ', m : 'em ', n : 'en ', o : 'oh ', p : 'pee ', q : 'cue ', r : 'are ', s : 'es ', t : 'tee ', u : 'you ', v : 'vee ', w : 'doubleyou ', x : 'ex ', y : 'why ', z : 'zee ', 1 : 'one ', 2 : 'two ', 3 : 'three ', 4 : 'four ', 5 : 'five ', 6 : 'six ', 7 : 'seven ', 8 : 'eight ', 9 : 'nine ', 0 : 'zero ', '<' : 'left-inequality ', '>' : 'right-inequality', ':' : 'colon ', ';' : 'semicolon ', '(' : 'left-parenthesis ', ')' : 'right-parenthesis ', ' ' : 'space ', '?' : '? ', '!' : '! ', '.' : '. ', ',' : ', ' } for (i in flipTable) { flipTable[flipTable[i]] = i } </script> It's code based on text flipper. Anyways, if you type in A, the output would be aye. How would I go about switching this script so when one puts in 'aye' the output is the letter A? Similar TutorialsThe statement does what I want it to do, except if there is multiple instances of the word, it only outputs one, how can I work it so all instances are output in red? (while still using .slice) var phrase = prompt("Enter a messate: ", 'Message'); var searchFor = prompt("Enter search text: ", 's'); var matchPhrase = ""; var searchIndex = -1; /* if there's a match, create a text string by * add the phrase text from before the match, * add <font> tags around the match text, * add the rest of the phrase from after the match */ searchIndex = phrase.indexOf(searchFor); if (searchIndex >=0 ) { // Copy text from phrase up till the match. matchPhrase += phrase.slice(0, searchIndex); matchPhrase += '<font color="red">' + searchFor + '</font>'; matchPhrase += phrase.slice(searchIndex + searchFor.length); phrase++ } else { matchPhrase = "No matches" } document.writeln(matchPhrase); Reply With Quote 01-31-2015, 09:08 AM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts Use a regular expression. I need help with a javascript calculation. I am a noobie developer as you will probably see by my script but here are my goals: I already have a working bmi calculator for my website where visitor will enter height and current weight to calculate their current bmi. then I want to have a reverse bmi calculator to grab the same height and weight from said bmi calculator to give a calculation with a fillable goal bmi (example: 18-24 "healthy bmi") to read out a goal weight for them to achieve. I have already figured out the first part of the bmi calculation now i just need the second calculation to grab the height and weight from original bmi calculator without needing to be filled in again and compute result in a second table. I will post code that I have come up with so far for the whole page. Thank you in advance for your help! [CODE] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> HCG Drops Fat Lose 1-2 pounds Per Day! </title> <style type="text/css"> #wrapall { width:1000px; align:center; margin-left: 7em; margin-right: 7em; } #navigationbar{ } #bmibar { width:973px; background-image:url(bmibar2.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:16em; margin:4px; } #Hcgborder { width:973px; background-image:url(index_15.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:17em; } #Hcgborder h3 { width:973px; background-image:url(index_12.jpg); background-repeat:no-repeat; background-position:left top; margin:0px; padding-left:4em; padding-top:8em; } p { background-image:url(index_13.jpg); background-repeat:repeat-y; background-position:left center; margin:0px; padding-left:4em; padding-right:4em; font:family"arial" } #bmiscale{ font-size:14px; padding-left:15px; } #Hcgborder2 { width:973px; background-image:url(index_19.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:0.5em; } #dhtmlgoodies_bmi_calculator{ width:180px; /* Width of entire calculator */ height:145px; /* Height of entire calculator */ font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; /* Fonts to use */ } #dhtmlgoodies_bmi_calculator .calculator_form{ /* Form */ width:180px; /* Width of form div */ float:left; /* Position the form at the left of the graph */ padding-left:5px; padding-right:5px; } #dhtmlgoodies_bmi_calculator input{ width:130px; } #dhtmlgoodies_bmi_calculator .calculator_form .textInput{ width:40px; /* Width of small text inputs */ text-align:right; /* Right align input text */ } .barContainer{ /* DIV for both the multicolor bar and users weight bar */ position:absolute; bottom:0px; border:0px solid #4ff; border-bottom:0px; text-align:center; vertical-align:middle; } .barContainer div{ /* colored div inside "barContainer */ border-bottom:1px solid #000; } .barContainer .labelSpan{ /* Label indicating users BMI */ background-color:#FFF; /* White BG */ border:1px solid #000; /* Black border */ padding:1px; /* "Air" inside the box */ font-size:0.9em; /* Font size */ } .clear{ /* Clearing div - you shouldn't do anything with this one */ clear:both; } </style> <script type="text/javascript"> var useCm = false; // Using centimetre for height, false = inch var useKg = false // Using kilos for weight, false = pounds var graphColors = ['#00baff','#02eb07','#ffb400','#ff0000']; var graphLabels = ['']; var labelsPerRow = 1; /* Help labels above graph */ var barHeight = 50; // Total height of bar var barWidth = 50; // Width of bars */ // Don't change anything below this point */ var calculatorObj; var calculatorGraphObj; var bmiArray = [0,18.5,25,30,60]; /* BMI VALUES */ var weightDiv = false; function calculateBMI() { var height = document.bmi_calculator.bmi_height.value; var weight = document.bmi_calculator.bmi_weight.value; height = height.replace(',','.'); weight = weight.replace(',','.'); if(!useKg)weight = weight / 2.2; if(!useCm)height = height * 2.54; if(isNaN(height))return; if(isNaN(weight))return; height = height / 100; var bmi = weight / (height*height); createWeightBar(bmi); } function createWeightBar(inputValue){ if(!weightDiv){ self.status = Math.random(); weightDiv = document.createElement('DIV'); weightDiv.style.width = barWidth + 'px'; weightDiv.className='barContainer'; weightDiv.style.left = Math.round((calculatorGraphObj.offsetWidth/2) + ((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px'; calculatorGraphObj.appendChild(weightDiv); var span = document.createElement('SPAN'); weightDiv.appendChild(span); var innerSpan = document.createElement('SPAN'); innerSpan.className='labelSpan'; span.appendChild(innerSpan); }else{ span = weightDiv.getElementsByTagName('SPAN')[0]; innerSpan = weightDiv.getElementsByTagName('SPAN')[1]; } var color = graphColors[graphColors.length-1]; for(var no = bmiArray.length-1;no>0;no--){ if(bmiArray[no]>inputValue)weightDiv.style.backgroundColor = graphColors[no-1]; } if(inputValue/1>1){ innerSpan.innerHTML = inputValue.toFixed(2); span.style.display='inline'; }else span.style.display='none'; var height = Math.min(Math.round(barHeight * (inputValue / bmiArray[bmiArray.length-1])),barHeight-10); span.style.lineHeight = Math.round(height) + 'px'; weightDiv.style.height = height + 'px'; } function validateField() { this.value = this.value.replace(/[^0-9,\.]/g,''); } function initBmiCalculator() { calculatorObj = document.getElementById('dhtmlgoodies_bmi_calculator'); calculatorGraphObj = document.getElementById('bmi_calculator_graph'); if(!useCm)document.getElementById('bmi_label_height').innerHTML = 'inches'; if(!useKg)document.getElementById('bmi_label_weight').innerHTML = 'pounds'; var heightInput = document.getElementById('bmi_height'); heightInput.onblur = validateField; var widthInput = document.getElementById('bmi_height'); widthInput.onblur = validateField; var labelDiv = document.createElement('DIV'); labelDiv.className = 'graphLabels'; calculatorGraphObj.appendChild(labelDiv); for(var no=graphLabels.length-1;no>=0;no--){ var colorDiv = document.createElement('DIV'); colorDiv.className='square'; colorDiv.style.backgroundColor = graphColors[no]; colorDiv.innerHTML = '<span></span>'; labelDiv.appendChild(colorDiv); var labelDivTxt = document.createElement('DIV'); labelDivTxt.innerHTML = graphLabels[no]; labelDiv.appendChild(labelDivTxt); labelDivTxt.className='label'; if((no+1)%labelsPerRow==0){ var clearDiv = document.createElement('DIV'); clearDiv.className='clear'; labelDiv.appendChild(clearDiv); } } var clearDiv = document.createElement('DIV'); clearDiv.className='clear'; labelDiv.appendChild(clearDiv); var graphDiv = document.createElement('DIV'); graphDiv.className='barContainer'; graphDiv.style.width = barWidth + 'px'; graphDiv.style.left = Math.round(((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px'; graphDiv.style.height = barHeight; calculatorGraphObj.appendChild(graphDiv); var totalHeight = 0; for(var no=bmiArray.length-1;no>0;no--){ var aDiv = document.createElement('DIV'); aDiv.style.backgroundColor = graphColors[no-1]; aDiv.innerHTML = '<span></span>'; var height = Math.round(barHeight * (bmiArray[no] - bmiArray[no-1]) / bmiArray[bmiArray.length-1]) - 1; aDiv.style.height = height + 'px'; graphDiv.appendChild(aDiv); } createWeightBar(1); } </script> <!-- function cal_bmi(lbs, ins){ h2 = ins * ins; bmi = lbs * h2/703 wtl = h2/703 * 24.9 f_bmi = Math.floor(bmi); diff = bmi - f_bmi; diff = diff * 10; diff = Math.round(diff); if (diff == 10){ f_bmi += 1; diff = 0; } bmi = f_bmi + "." + diff; return bmi; } function compute(){ var f = self.document.forms[0]; w = f.wt.value; v = f.htf.value; u = f.hti.value; // Format values for the calculation if (!chkw(u)){ var ii = 0; f.hti.value = 0; } else { var ii = parseInt(f.hti.value); } var fi = parseInt(f.htf.value * 12); var i = fi + ii; // Do validation of remaining fields if (!chkw(v)){ alert("Please enter your height."); f.htf.focus(); return; } if (!chkw(w)){ alert("Please enter your weight."); f.wt.focus(); return; } // Perform calculation f.bmi.value = cal_bmi(w, i); f.bmi.focus(); } function chkw(w){ if (isNaN(parseInt(w))){ return false; } else if (w < 0){ return false; } else{ return true; } } // --> </style> </head> <body> <div id="wrapall" align="center"> <img src="index_01_01.jpg" alt="Hcg drops fat banner"> <br/> <div id="navigationbar"> <a href="http://www.hcgdropsfat.com"><img src=hcghomeog.jpg border=0></a> <img src="hcgblogo.jpg" alt="Hcg blog"/> <img src="hcgfaqo.jpg" alt="Hcg faq"> <img src="hcgresourceso.jpg" alt="Hcg resources"> <img src="hcgtestimonialso.jpg" alt="Hcg testimonials"> <img src="hcgsupporto.jpg" alt="Hcg support"> <img src="hcgordero.jpg" alt="Hcg order"> <div id="bmibar"> <div style="position: absolute; top: 515px; left: 170px"; style="font-family: arial"; align="left";> How much is your weight in <br/>relation to your height <br/> <!--BMI CALCULATOR SCRIPT--> <div id="dhtmlgoodies_bmi_calculator"> <div class="calculator_form"> <form name="bmi_calculator"> <table> <tr> <td><label for="bmi_height">Height</label>:</td><td><input class="textInput" type="text" id="bmi_height" name="bmi_height"> <span id="bmi_label_height">cm</span></td> </tr> <tr> <td><label for="bmi_weight">Weight</label>:</td><td><input class="textInput" type="text" id="bmi_weight" name="bmi_weight"> <span id="bmi_label_weight">kg</span></td> </tr> <tr> <td colspan="2"><input type="button" onclick="calculateBMI()" value="Find BMI"></td> </tr> </table> </form> </div> <div class="calculator_graph" id="bmi_calculator_graph"> </div> </div> <script type="text/javascript"> initBmiCalculator(); </script> </div> <div style="position: absolute; top: 515px; left: 405px"; style="font-family: arial"; align="left";> What is your BMI category? <br/>This will help determine <br/>how much you need to lose <br/><br/><div id="bmiscale">Underweight = Under 18.5 <br/>Normal weight = 18.5 – 24.9 <br/>Overweight = 25 – 29.9 <br/>Obesity = 30 or more <br/><br/> </div></div> <div style="position: absolute; top: 515px; left: 640px"; style="font-family: arial"; align="left";> Calculate approximately how <br/>much weight you should lose<br/> to be at a healthy BMI <!--REVERSE BMI CALCULATOR--> <td width="81%" valign="top"> <br/><div align="center" class="page_header">Reverse BMI Calculator</div><br/> <div align="center" class="main_text"></div> <form action="" method="post" name="BMI_input" class="main_text" id="BMI_input"> <div style="text-align: center;"><font face="Arial, Helvetica, sans-serif">Target BMI:<b> <input id="FormsEditField4" type="text" name="wt" value="24" size="3" maxlength="2" /> <br /> </b></font></div> <div style="text-align: center;"> <font face="Arial, Helvetica, sans-serif"> <input type="button" name="FormsButton1" value="Find Target Weight" id="FormsButton1" onclick="self.compute()" /> </font></div> <div style="text-align: center;"><font face="Arial, Helvetica, sans-serif">This is your Target Weight: <br /> <input id="FormsEditField5" type="text" name="bmi" value="" size="4" maxlength="5" /> </font></div> </div> </div> <div id="Hcgborder"> <h3></h3> <p align="left"><b> WHAT IS HCG? </b><BR/><BR/>In simple terms: its a hormone protein produced by pregnant women that when used as a homeopathic dietary supplement, will assist in a revolutionary cure to the traditional diet routine. <BR/><BR/><b>HCG is so unique from other diets in 3 major ways: </b> <br/><BR/><img src="muscletissue.jpg" alt="practice"style="float:right;" width="250px" height="250px"/> 1. USES HIGHEST FAT AS PRIMARY FUEL SOURCE FOR THE BODY - it begins to break down the abnormally high body fat as the primary fuel source (BURNS ALOT OF FAT!) <BR/>2. DOESNT EAT AT VITAL MUSCLE TISSUE - it will preserve and maintain lean body muscle (without HCG THE BODY WOULD DEPLETE VITAL MUSCLE TISSUE ON A LOW CALORIE DIET. Also if you burn muscle you also lose metabolism for each pound of muscle you lose you also lose 50 calories of metabolism) <BR/>3. WHILE MOST DIETS SLOW METABOLISM HCG ACTUALLY MAINTAINS IT EVEN AFTER THE DIET - because hcg maintains lean muscle and maintains metabolism, you keep your metabolism in check long after the diet program so you reset your bodys roaming weight. <BR/><BR/>THE HOMEOPATHIC DROPS YOU WILL FIND ON OUR SITE ARE ALL NATURAL <br/><BR/><b>HOW LONG HAS IT BEEN AROUND?</b> <BR/><BR/>HCG or (Human chorionic gonadotropin)<img src="nicefigure.jpg" alt="Hcg stored fat" style="float:right;" width="250px" height="250px"/> is a protein hormone </div><!--p1--> </div><!--Hcgborder--> <div id="Hcgborder2"> <p><b>hello</b></p> <p>Hello again</p> </div><!--Hcgborder2--> </div> </div><!--wrapall--> </body> </html> [CODE] Hi Fellows, Just a quick question, is there a fucntion or a way to get the current date and time of a unix datetime stamp in javascript? I use something like Code: var end_time = end_dateTime.getTime(); but now I need a way to find out what the current date and time is after modifying the end_time variable. Thanks a lot!!! i just read the other thread and i want the reverse affect. the slideshow opens in a new window and thats not what we want because the link is to a persons profile page. we dont want two versions of the site open at once. this is the slideshow that client did on his own then i got the project. http://www.dynamicdrive.com/dynamici...nslideshow.htm Code: imagearray: [ ["pool.jpg"], ["http://mysite.com/cave.jpg", "http://cnn.com"], ["fruits.jpg", "http://cnn.com", "_new"], ["dog.jpg", "", "", "This image has a description but no hyperlink"] //<--no trailing comma after very last image element! ], i see "_new"], in there but i dont know if there is a command for self is it _self .. im not sure.. i assume it is different than the html target code. so how do i make it open in the same window just like target = self sorry had to change the target to non coded format to show up right in this thread Howdy Community, I have spent the past 4 hours strait looking for and trying to modify an accordion style vertical menu who's elements slide out of the top and up instead of the normal slide out of the bottom and down action. I would like it in jQuery, but at this point I will take any library. Thanks for your help. I know some have wondered "What have you tried making work".. jQuery Tools, Jquery UI and about 3 other scripts that looked updateable. All I couldn't get to work. I also made an attempt to fake an accordion using show/hide toggles and this sorta worked, but it didnt have the nice slide as well as my data didnt move on page in the right direction. Headache!!! Help!! Thanks, Cesar I have been searching for a long time but have been unsuccessful on how to develop a drop down menu but have the menu items show in a list above the main nav. Not below. I really like the way this functions: http://www.sohtanaka.com/web-design/examples/toggle/ But I would like the item in the list to appear above the main nav so it animates up not down. Can anyone help me on how to alter this js code to perform this task? Here is the jQuery file link: http://code.jquery.com/jquery-latest.js I tried going through this js file but it very complex. Can anyone tell me what I need to change to have the animation roll up instead of down? Any help would be most appreciated. I thought I knew how, but I'm unclear how to get this function to display: "document.getElementById("txtHint").innerHTML=xmlhttp.responseText;" inside the div. Will you show me please? Code: xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var div = document.createElement('div'); div.setAttribute('id', 'txtHint'); div.setAttribute("style","background-color:red;"); div.style.width = '300px'; div.style.height = '100px'; document.getElementById("txtHint").innerHTML=xmlhttp.responseText; //var txt='hello world!'; document.getElementsByTagName('body')[0].appendChild(div); document.getElementById('textHint').innerHTML=txt; } } hi, The following script is supposed to display an output of 5000 or more lines but it stucks if output is more than 3000 lines. so is it possible to achieve such a program..? or does it depend on the computer CPU? thanks PHP Code: <body bgcolor=9999cc> <script> count=0; function yaz() { document.getElementById("kutu").innerHTML=""; document.getElementById("bt").value=""; count=0; for(var a=0;a<=4;a++){ for(var b=0;b<=4;b++){ for(var c=0;c<=4;c++){ for(var d=0;d<=4;d++){ for(var e=0;e<=4;e++){ for(var f=0;f<=4;f++){ for(var g=0;g<=4;g++){ for(var h=0;h<=4;h++){ if((a<b)&(c<d)&(e<f)&(g<h)) { count++; document.getElementById("kutu").innerHTML+=count+"--"+a+".."+b+".."+c+".."+d+".."+e+".."+f+".."+g+".."+h+"<br>"; } } }} }} }} } document.getElementById("bt").value="there are.."+count+"..lines "; } </script> <center> <input type="button"id="bt" value="gooo" onclick="yaz()"> <div id="kutu"align="center" style="border-style:solid;border-width:2;border-color:blue;background-color:pink;width:400;color:green;"> </div> </body> </html> Hi, I need to show the results in a proper manner. now I'm testing these results as a alert. But I need to show them in a table and I have to sort them according to the ascending order. Do you have any suggestions? hi, I'm a new guy to computer science and info system and I am taking an intro class to it right now. I was asked to make a simple "enter the word in the box" quiz and I can't get the output! it's driving me crazy and I get "ur score is [object HTMLInputElement]out of 3" at the bottom when I had it say, "Your score is:".. here is my html coding and no, I'm not asking for anyone to do my homework. I just want to make this work! be easy. NOTE: I'm using Apple over again because I want to get the coding down and then I will change up the quiz and the answers Code: <html> <head> <title> COMSC 100 Assignment 9 by Me </title> <script> function getInputAsText(_id){return document.getElementById(_id).value} function getInputAsNumber(_id){return parseFloat(document.getElementById(_id).value)} function setOutput(_id, _value){document.getElementById(_id).value = _value} function calculate() { // declare all variables var myResult1 var myResult2 var myResult3 var resultAsText // get variable's value myAnswer1= getInputAsText("myResult1") myAnswer2= getInputAsText("myResult2") myAnswer3= getInputAsText("myResult3") // perform concatenation if (myAnswer1.toLowerCase() == " Apple" .toLowerCase()) { score= score + 1 // got this one right myResult1= "correct" } else { myResult1 = "Wrong! It's Apple" } if (myAnswer2.toLowerCase() == "Apple".toLowerCase()) { score= score + 1 // got this one right myResult2 = "correct" } else { myResult2 = "Wrong! it's Apple" } if (myAnswer3.toLowerCase () == "Apple".toLowerCase()) { score = score + 1 //got this one right myResult3 = "correct" } else { myResult3 = "Wrong! It's Apple" } // write output value setOutput("score", "Your score is " + score + "out of 3") setOutput ("myResult1",myResult1) setOutput ("myResult2",myResult2) setOutput ("myResult3",myResult3) } </script> </head> <body> Directions:<br> Answer the three questions and press go <br> Your score will appear<br> Input values:<br> 1. A byte is how many bits?<input id="myResult1"><br> 2.Steve Jobs heads what company?<input id="myResult2"><br> 3.Bill Gates heads what company? <input id="myResult3"><br> <input type="submit" value="go" onclick="calculate()"><br> Output<br> Result #1:<input id= "myResult1" size="25"><br> Result #2:<input id= "myResult2" size="25"><br> Result #3:<input id= "myResult3" size="25"><br> Your sco <input id= "score" size="25"> </body> </html> Could someone take a look at this and tell me what I am doing wrong please? I have an onSubmit function that calls the following code. It works fine spitting out the return values, but the section with the "textareas for" statement is displayed after everything else. (I understand why) However, I want it to display in the order with the rest of the fields. Ideally it should be a part of the "inputArray for" statement. Is there an easy way to join these two for statements and spit everything out in the order from the original form? Thanks Code: <script> function showComposer() { var textstring = ''; var textAreaArray = ''; var textareas = document.repairform.getElementsByTagName("textarea"); var inputArray = document.repairform.getElementsByTagName("input"); for (i=0;i<inputArray.length;i++) { if (inputArray[i].getAttribute('class') == 'info') { textstring += "<table><tr><td><strong>" + inputArray[i].name + " : </strong></td>" + "<td>" + inputArray[i].value +"</td></tr></table>"; } else if((inputArray[i].getAttribute('type') == 'text') || (inputArray[i].getAttribute('type') == 'radio' && inputArray[i].checked)) { textstring += "<table><tr><td><strong>" + inputArray[i].name + " : </strong></td>" + "<td>" + inputArray[i].value +"</td></tr></table>"; } } for (i=0;i<textareas.length;i++) { textAreaArray += "<table><tr><td><strong>" + textareas[i].name + " : </strong></td>" + "<td>" + textareas[i].value +"</td></tr></table>" + '\n'; } var stringArray = textstring.concat(textAreaArray); var composer = new NKMailComposer(); composer.setRecipient(""); composer.setSubject("ESTIMATE SHEET AND REPAIR ORDER"); composer.setBody (stringArray, 1); composer.show(); document.repairform.submit(); } </script> Hi Guys, Hope you can help. How do you simply output the current url in the browser i.e if i am in google.com I want google.com outputted and so on. Also on multilanguage sites if my url is say www.mydomain.com/en/about.html or http://www.mydomain.com/en/animals/h...stallions.html I want to be able to manipulate the url so I can change en to fr for example when I jump between english and french pages. I want users to be able to switch the language of that particular page by clicking a link. I need to be able to switch segment one of the url (en,fr,de etc...)dynamically somehow instead of hardcoding a link into each page. Any ideas? THANKS Hey guys, if someone could help point me in the right direction that would be great. I cant get seem to get this array to print the numbers 1 to 15 out. When I preview I get nothing, anyone know what I am doing wrong? Thanks to those that reply. thanks got it I've tried a couple of different scripts, and I'm getting the same result, so I know I must just be missing something. I'm very new to this, so I'm not figuring it out. I want a text box to show the results of an increment counter. Every time I click a button, the number in the text box increments by one. I know it sounds simple, but it's not working. Help? My code is below: Code: <style type = "text/css"> .tbsize { width: 30px; border: 3px; padding: 10px } </style> <script type="text/javascript"> var i=0; function increase() { ++i; } </script> </head> <body> <div id = "tbsize" class = "tbsize"> <form onsubmit = "return false" action = ""> <table> <td><input type = "text" id = "addone" /></td> <td><input type = "submit" value = "Click to add One" onclick="increase()"></td> </table> </form> </div> </body> </script> Hey. I need some javascript help. Quite confused. So I made a .js file with the following contents. function cost (){ var q = "How much do you want to spend for a Hotel?" var newb1 = prompt(q, "") var q = "How much do you want to spend for Food?" var newb2 = prompt(q, "") var q = "How much do you want to spend for Activities?" var newb3 = prompt(q, "") var q = "How much for Shopping?" var newb4 = prompt(q, "") sum2 = parseInt(newb1) + parseInt(newb3) + parseInt(newb4) document.getElementById("cost").innerHTML = "Total Price :" +sum2 } Then I inserted it into my homepage using this. <script type="text/javascript" src="hotelprice.js"></script> The prompt comes up, asks for all of the inputs. But it doesn't display the output, which should have simply added them all together. How do I fix this? I have a very basic calculator that I am trying to make that takes info from radio buttons (i.e. 1 for bad 5 for good) and outputs an average or score at the end, but its not working correctly. I have changed the last line to output what the total number is not the average, to see if it is outputting the correct number, and its not... It says "[object HTMLInputElement]"... Any thoughts will be greatly appreciated! Thanks! Code: function calcScore(){ var op1 = document.getElementsByName('form[q1]'); var op2 = document.getElementsByName('form[q2]'); var op3 = document.getElementsByName('form[q3]'); var op4 = document.getElementsByName('form[q4]'); var op5 = document.getElementsByName('form[q5]'); var op6 = document.getElementsByName('form[q6]'); var op7 = document.getElementsByName('form[q7]'); var op8 = document.getElementsByName('form[q8]'); var op9 = document.getElementsByName('form[q9]'); var op10 = document.getElementsByName('form[q10]'); var op11 = document.getElementsByName('form[q11]'); var op12 = document.getElementsByName('form[q12]'); var op13 = document.getElementsByName('form[q13]'); var op14 = document.getElementsByName('form[q14]'); var op15 = document.getElementsByName('form[q15]'); var op16 = document.getElementsByName('form[q16]'); var op17 = document.getElementsByName('form[q17]'); var op18 = document.getElementsByName('form[q18]'); var op19 = document.getElementsByName('form[q19]'); var op20 = document.getElementsByName('form[q20]'); var op21 = document.getElementsByName('form[q21]'); var op22 = document.getElementsByName('form[q22]'); var op23 = document.getElementsByName('form[q23]'); var op24 = document.getElementsByName('form[q24]'); var op25 = document.getElementsByName('form[q25]'); var op26 = document.getElementsByName('form[q26]'); var op27 = document.getElementsByName('form[q27]'); var op28 = document.getElementsByName('form[q28]'); var op29 = document.getElementsByName('form[q29]'); var op30 = document.getElementsByName('form[q30]'); var op31 = document.getElementsByName('form[q31]'); var totalscore = document.getElementById('score'); totalscore.value = 0; totalscore.value = parseInt(totalscore.value); var totalnum = document.getElementById('score1'); totalnum.value = 0; totalnum.value = parseInt(totalnum.value); for (var i=0; i < op1.length; i++) { if (op1[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op1[i].value); } } for (var i=0; i < op2.length; i++) { if (op2[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op2[i].value); } } for (var i=0; i < op3.length; i++) { if (op3[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op3[i].value); } } for (var i=0; i < op4.length; i++) { if (op4[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op4[i].value); } } for (var i=0; i < op5.length; i++) { if (op5[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op5[i].value); } } for (var i=0; i < op6.length; i++) { if (op6[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op6[i].value); } } for (var i=0; i < op7.length; i++) { if (op7[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op7[i].value); } } for (var i=0; i < op8.length; i++) { if (op8[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op8[i].value); } } for (var i=0; i < op9.length; i++) { if (op9[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op9[i].value); } } for (var i=0; i < op10.length; i++) { if (op10[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op10[i].value); } } for (var i=0; i < op11.length; i++) { if (op11[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op11[i].value); } } for (var i=0; i < op12.length; i++) { if (op12[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op12[i].value); } } for (var i=0; i < op13.length; i++) { if (op13[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op13[i].value); } } for (var i=0; i < op14.length; i++) { if (op14[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op14[i].value); } } for (var i=0; i < op15.length; i++) { if (op15[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op15[i].value); } } for (var i=0; i < op16.length; i++) { if (op16[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op16[i].value); } } for (var i=0; i < op17.length; i++) { if (op17[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op17[i].value); } } for (var i=0; i < op18.length; i++) { if (op18[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op18[i].value); } } for (var i=0; i < op19.length; i++) { if (op19[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op19[i].value); } } for (var i=0; i < op20.length; i++) { if (op20[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op20[i].value); } } for (var i=0; i < op21.length; i++) { if (op21[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op21[i].value); } } for (var i=0; i < op22.length; i++) { if (op22[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op22[i].value); } } for (var i=0; i < op23.length; i++) { if (op23[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op23[i].value); } } for (var i=0; i < op24.length; i++) { if (op24[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op24[i].value); } } for (var i=0; i < op25.length; i++) { if (op25[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op25[i].value); } } for (var i=0; i < op26.length; i++) { if (op26[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op26[i].value); } } for (var i=0; i < op27.length; i++) { if (op27[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op27[i].value); } } for (var i=0; i < op28.length; i++) { if (op28[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op28[i].value); } } for (var i=0; i < op29.length; i++) { if (op29[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op29[i].value); } } for (var i=0; i < op30.length; i++) { if (op30[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op30[i].value); } } for (var i=0; i < op31.length; i++) { if (op31[i].checked) { totalnum.value=parseInt(totalnum.value)+parseInt(op31[i].value); } } totalscore.value = totalnum; } Hi! I'm very new to javascript and a bit stuck with trying to calculate values from functions together. Let's say I have three functions. Each function is given a value and the goal is to calculate all the values together in a variable. This is what I have so far: Code: function numberAdd1 () { addValue = 1; return.addValue; } function numberAdd2 () { addValue = 2; return.addValue; } function numberAdd3 () { addValue = 3; return.addValue; } How would I now calculate the return value of each funtion together and store the result in a variable? I want to write a code. in which I select the AC Temperature By Radio Buttons. then I observe the Saving energy by Bar Graph with out submitting the Form. As I change the Input, automatically, Output should change what should be code in HTML or Javascript so that I may observe effect of the change of Temperature on saving energy. thanks. Hi, I have 3 functions. I do not know how to have 2 functions recognize the output of an array from the other function. All of this revolves around input(text boxes). What is the array's output? In other words, how do I get the newly added textboxes recognized by the initial functions - what are they called? I have tried adding names like "No. of Hours[1]"; "No. of Hours(1)"; or,"No. of Hours1"; but none of that works. For example, one of the inputs is called "No. of Hours". That is the input textbox on the web page. When the add new rows array is invoked it adds new input textboxes and the new element is Code: el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); What is this new input/element called so that I can refer to it for the coded function shown below? The first function provides validation for user input. Code: function checkQuarters( fld ) { var val = parseFloat(fld.value); if ( isNaN(val) || ( val*4 != Math.floor(val*4) ) ) { alert("Value must be a numeric and a multiple of 0.25"); return false; } return true; } </script> The input for the above function is Code: <td> <form style="width: 5px; height: 1px;"> <input type="text" name="No. of Hours" id="No. of Hours" style="width: 70px;" onblur="checkQuarters(this);" /> </form></td> The array outputs added textboxes thusly, Code: new_rows[row_count]['cell3']=sel; var cellRight = row.insertCell(3); var el = document.createElement('input'); el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); new_rows[row_count]['cell']=el; row_count++; The other function uses a JQuery for a datepicker. Code: <script type="text/javascript"> $(function() { $("#startdate").datepicker(); $("#enddate").datepicker(); }); </script> The input is this. Code: <td><input style="width: 70px" type="text" id="startdate"></td> <td><input style="width: 70px" type="text" id="enddate"></td> I am lost on this and could really use some help and guidance. Thanks, John |