JavaScript - Image Call With Highest Value
hey there. the script im trying to write is used to take the values from four separate forms and display an image based on the highest value. it looks like this.
Code: <script type="text/javascript"> var val = Math.abs(document.getElementById("mytext1").value); var val2 = Math.abs(document.getElementById("mytext2").value); var val3 etc var val 4 etc var showImg = document.getElementById("image1").src = "default.jpg" document.getElementById("image1").src = "default.jpg" // check + values for right sph if (val >= .25 && val <= 3.5) {document.getElementById("image1").src = "r39.gif"} if (val >= 3.75 && val <= 5.50) {document.getElementById("image1").src = "pol.gif"} // check - values for right cy if (val <= -.25 && val >= -3.5) {document.getElementById("image1").src = "r39.gif"} if (val <= -3.75 && val >= -5.5) {document.getElementById("image1").src = "pol.gif"} // check + values for left sph if (val2 >= .25 && val2 <= 3.5) {document.getElementById("image1").src = "r39.gif"} if (val2 >= 3.75 && val2 <= 5.50) {document.getElementById("image1").src = "pol.gif"} // check - values for left cy if (val2 <= -.25 && val2 >= -3.5) {document.getElementById("image1").src = "r39.gif"} if (val2 <= -3.75 && val2 >= -5.5) {document.getElementById("image1").src = "pol.gif"} etc etc } </script> <input type = "text" id = "mytext1" > <input type = "text" id = "mytext2" /> <input type = "text" id = "mytext3" > <input type = "text" id = "mytext4" > <img src="calculate.gif" onclick="showImg()"> anybody know how i go about getting the highest value checked and the resulting image displayed. thanks in advance. Similar TutorialsHello, I am trying to use a for loop to call images of custom text. For example, I have images named uppera.png and lowera.png for a custom font. I need the image of the letter to show up as they type into a text area, but also have backspace work correctly to delete the last image added. Here is the code I have thus far: <script type="text/javascript"> function callimage() { var chars = document.getElementById('userinput').value.split(""); for (i=0; i < chars.length; i++) { if (chars[i] == "A") { var image = "uppera.png"; } if (chars[i] == "a") { var image = "lowera.png"; } ... if (chars[i] == "9") { var image = "9.png"; } document.getElementById('visual').innerHTML = document.getElementById('visual').innerHTML + '<img src="' + image + '"/>'; } } </script> <input type="text" maxlength="20" id="userinput" onkeyup="callimage()"/> <p id="visual"> </p> When I test this out it takes the previously entered text and adds it to the new text and combines them. For instance if you entered "a" it would show up as "a"; if you entered "a" again it would show up as "aaa" and then "aaaaaa" and so on. Also, it will add the existing characters again if any key is pressed, like just shift. I think I would need to write an else statement to fix that part, but I don't know what to put there, either. Any ideas on how I could fix this one? Thanks! Hi Guys, I am trying to make a change to my website so when someone clicks on the chinese flag image, for example, a function which put the clock forward a few hours. This is what the code I have got at the moment: <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=en'; ?>"><img src="images/uk.gif" title="english" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=zh'; ?>"><img src="images/ch.gif" title="chinese" onclick="chinatime()" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=ja'; ?>"><img src="images/jap.gif" title="japanese" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=kk'; ?>"><img src="images/kaz.gif" title="kazakh" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang='.$most_preferred; ?>">Browser Set</a></td> </tr> <tr> <td colspan="5"> <p class="meta"><span class="date"><script type="text/javascript"> var currentTime = new Date() var minutes = currentTime.getMinutes() var hours = currentTime.getHours() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() function chinatime() { hours = hours + 5 } if (minutes < 10) minutes = "0" + minutes document.write(day + "/" + month + "/" + year + " " + hours +":"+minutes) </script> Many Thanks Hi, Firstly, I would like to introduce myself. I am new to the application framework in sencha and JS. Acutally i have to pop an image on click of the text. I checked some of the same codes and wrote this code in sencha javascript. can any one please check what's wrong with this code and let me know how to call this function from html code. function showEditWindow() { var win = new Ext.Window({ title: 'image', width: 100, height: 100, html: '<img src=\"p1.png\"></img>', }); win.show(); return win; }; Basically I want to have a different background image for every time of the day. The function by itself works okay with onclick or onload placed in body. Code: function changesky() { document.getElementById("sky").style.background="url(back_morning.jpg) repeat-x"; } What I want to do is have my background change in addition to a message. So instead of just "Good Morning" text I also want the background to change. Code: if (time>=4 && time<12) { document.write ("<p>Good Morning!</p>"); document.getElementById("sky").style.background="url(back_morning.jpg) repeat-x"; } Tried this, but it didn't work so what's the format for calling a function inside of an if statement? Or what other method should I use to do this? Hi i need to find the highest average from all of the averages entered in this code, but i have to use an if statement only, no arrays. Could some one help please? Code: // ** Work out average ** // average= readingSum/totalReadings // ** Put average into a category and display everything ** // if(average<5) { catergory1=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Dry"); } else if(average>=5 && average<20) { catergory2=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Normal"); } else if(average>20) { catergory3=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Wet"); } // ** Find Highest average ** // Thanks. I'm having a hard time trying to get this script to work. I am trying to write a script that finds the highest of 5 numbers and places the highest number in the last textbox. Can anybody tell me what I am doing wrong? Code: <HTML> <HEAD> <TITLE>COMSC-100-1241 - Assignment #10 - Using "Greater Than" And "Less Than" Logic</TITLE> <SCRIPT TYPE="text/JavaScript"> function Go(code){ var number1 var number2 var number3 var number4 var number5 var highest var max number1 = parseFloat(document.getElementById("number1").value); number2 = parseFloat(document.getElementById("number2").value); number3 = parseFloat(document.getElementById("number3").value); number4 = parseFloat(document.getElementById("number4").value); number5 = parseFloat(document.getElementById("number5").value); max = parseFloat(document.getElementById("max").value); if (code == 0){ } if (max < number1){ max = number1 } if (max < number2){ max = number2 } if (max < number3){ max = number3 } if (max < number4){ max = number4 } if (max < number5){ max = number5 } document.getElementById("max").value = highest } </SCRIPT> </HEAD> <BODY> <TABLE BORDER="1" WIDTH="500" ALIGN="center"> <TR> <TD> <DIV ALIGN="left"> <B>Instructions: </B> Answer the three questions and press "GO". Your score will appear. <BR> <BR> <B>Input Values: </B> <BR> <B>First Number:</B> <INPUT id="number1"> <BR> <B>Second Number:</B> <INPUT id="number2"> <BR> <B>Third Number:</B> <INPUT id="number3"> <BR> <B>Fourth Number:</B> <INPUT id="number4"> <BR> <B>Fifth Number:</B> <INPUT id="number5"> <BR> <INPUT TYPE="Submit" VALUE="GO!" onClick="Go(0);"> <BR><BR> <B>Output Values: </B> <BR> <B>Highest Number:</B> <INPUT id="highest"> </FORM> </DIV> </TD> </TR> </TABLE> </BODY> </HTML> Hey friends, I'm writing a program but I'm having issues. I need to write a program that asks for 3 different numbers (prompt boxes) and determine which number entered was the highest and the 2nd highest. I know what to do for the input and output but I don't know what to do during the processing.
So if I have three dollar amounts like .... a = 1,222.00; b = 1,323.00; c = ; d = 1,222.00; How can I alert the highest variable even though there may be 1 or more of them? Code: <SCRIPT LANGUAGE = "JAVASCRIPT"> var contestantNamesArray = ['Tom and Nazia', 'Pat and Dan', 'Sandra and Kofi', 'Ian and Adele', 'Paul and Costas']; var judgesPointsArray = [2,1,5,4,3]; var audiencePointsArray = [4,5,2,3,1]; //code to declare a new array to store the combined points for each couple var combinedPointsArray=new Array(); //code to calculate the combined points for each couple and store it in the combined points array for (i = 0; i <= 4; i++) { combinedPointsArray[i] = judgesPointsArray[i] + audiencePointsArray[i]; //code to find and output the maximum value in the combined points array } var winner = [0]; //set first pair as default winner for (i = 1; i <= 4; i++) { //start with second pair if (combinedPointsArray[i] => combinedPointsArray[winner[0]]) { //compare to first in the winners winners = [i]; //new high score }else if (combinedPointsArray[winner] == combinedPointsArray[i]) { winners[winners.length] = i;//add to highest tie } //danceoff between all numbers in winner array }//for for(i=0;i<winners.length;i++){ document.write(winners[i]+", "); document.write(i); } </SCRIPT> I am having trouble with this program, I cant seem to figure out why this is not working. Basically i need it to loop though the array and find who has the highest points / if more than one have the same points so i dance off is required. Can someone please lend a hand driving me mad. Regards, I've written a program which will prompt for a number of cities, Prompt for the name of the city, then prompt for the number of snowfall readings of that city, and then prompt for each of these individual snowfall readings of that city. From this, it adds up each of the individual snowfall readings of that city, and will calculate an average by dividing this figure [the total snowfall] by the total number of readings for that city. This average is used to then classify the city as "not snowy", "mild", or "blizzard". I'm happy to PM my code to anyone willing to help out, as I realise this is a complex structure to visualise perhaps, but I can't post it publicly. I now have to select the city with the highest average, and name it in an alert output. How is this possible. Note, I'm not allowed to use functions or arrays. Prompts, alerts, if-then-else, for and while loops are all I can use. Hi, I am hoping I just need to be pointed in the right direction with this. I have Page1. When Page1 body onloads it uses Ajax to call PartA Within PartA I have a message board so members can write messages which will be sent to my database in PartA[1] and immediately posted for view on to PartA[2]. As I want to have my request to the server updating regularly I want to have PartA[2] on a timed loop to refresh - I do not need the content of PartA[1] to refresh. So the order of events would look like this: Page1 | onload call | v PartA / \ V V PartA[1] PartA[2] (loads once) (constantly refreshes) What I am not sure about is that I have <body> and <head> attributes in Page1 only. I have already used my body onload to call PartA (and can't use it to call PartA[2] before PartA has loaded anyway). I do not want the user to have to click a button or do anything to call up PartA[2]. So my question is how would I get PartA[2] to automatically load within PartA? I hope I have made this clear, but if I haven't let me know and I will try again. Hello all, I am a newbie to api and I want to bring job website into my site using that job website's api. They provide calling url to the xml api to get response. But I dont to know how to get response through javascript. Can you please help me to call that api through javascript or java? Hope that it is simple to you. Thanks in advance... I'm trying to implement this 'ajax' script, however i'm getting the following error: function expected line 25. And I'm not the only person who is getting this error message :S How can the code be altered so it will work? Also the script isn't executed when I change onclick in onload :S How come and how can I change it so that it will be executed on launch? http://chriscook.me/web-development/...icking-a-link/ http://www.zooprinting.com/welcome the section with 5 things that rotate starts with "free design online" i need to make an element like that on my site, and i'm pretty handy at googling until i find the script i'm looking for and making it work, but i can't figure out what in the world to call that. it's commonly used but i just can't seem to get my search terms right. anyone know where i can find said script? Right for day's i've searching for a jQuery/js/ajax script that opens like facebooks box where you can delete things update posts and so on... But i don't want that facebox thing i want a tut where i can buy things that will insert into the database and delete things and sooo on... I've made the box i just want the script for it.... I'm not good with js/jQuery/ajax.... Thanks. hi i'm trying to call a web service from java script code stored NOT in Html but in an extenarl file .js. My code is this: service.useService("http://localhost:10000/WebS_cod_01/WebS_codEurService.asmx?wsdl", "WebS"); Photo = service.WebS.callService("webS_codEurProcessWS" , photoID); checking with Firebug i find this message: "service is not defined" where i'm wrong ? thanks in advance Hello. Started my massive JavaScript career just yesterday and the forums I frequent still lack a proper BB-code hide-tag, so I figured I'd try make it in JavaScript, since HTML is allowed on there. This is what I did: Code: <script type="text/javascript"> function show() { document.getElementById('silHideTextTag').innerHTML='Hidden text!!'; document.getElementById('silHideTextBtn').value='Hide'; document.getElementById('silHideTextBtn').onclick='hide()'; } function hide() { document.getElementById('silHideTextTag').innerHTML=' '; document.getElementById('silHideTextBtn').value='Show'; document.getElementById('silHideTextBtn').onclick='show()'; } </script> <input type='button' id='silHideTextBtn' onclick='show()' value='Show'/> <div id='silHideTextTag'> </div> The button labelled "Show" appears fine, when I click it it becomes "Hide" and the text "Hidden text!!" is shown. However, when I click the button again, nothing happens at all. I don't quite understand where the problem is. Thanks in advance for any clues. Best regards, Zyl Hello, if in a webpage is included a javascript file (for example code.js) can I from my browser call a function contained in code.js and will it works correctly? I'm not meaning that the function is called in the page with or without a link to click, but it is only in code.js! Thank you! My problem is that I am trying to call an function within an SWF. Now, I already know how to setup my SWF and that isn't the problem. The problem is that when I try to call the function using Javascript, I am told that the function doesn't exist. I'll show you the code right here. Code: function AudioPlayerEmbed( e ) { if ( e.success ) { e.ref.LoadAudio( 'http://therevolve.com/upload/userfiles/Music/Alec_Smith1.mp3' ); } } swfobject.embedSWF("player/MP3Player.swf", "flash", "300", "90", "9.0.0", "player/expressInstall.swf", null, null, null, AudioPlayerEmbed ); HOWEVER, when I put some alert before the call, it happens to work. What is going on? Code: function AudioPlayerEmbed( e ) { alert("A"); if ( e.success ) { e.ref.LoadAudio( 'http://therevolve.com/upload/userfiles/Music/Alec_Smith1.mp3' ); } } swfobject.embedSWF("player/MP3Player.swf", "flash", "300", "90", "9.0.0", "player/expressInstall.swf", null, null, null, AudioPlayerEmbed ); Here is a live example. Any help would be appreciated. If you need more information, I can provide it. |