JavaScript - Delayed Action Type Thing.
Code:
var c=0; var i=0; function timedCount() { document.getElementById('txt').innerHTML=c; c++; setTimeout("timedCount()",500); } function expand() { while (i<=10) { timedCount(); i++; } } For some reason the innerHTML number starts at 10 because of the while. I want it to start from 0 and stop when at 10... Similar TutorialsI know very little JavaScript (I can modify a script slightly, but I can't write one), so I am asking for your help. I want to place a textarea on a web page. This textarea would have attributes to make it so that if you pressed "i", it would come out as "c", or if you pressed "]" it would appear as "=", and so on. (If you're wondering, I want to make it work like the Dvorak keyboard layout). I also would like a button to copy the text in the textarea to the clipboard. Thank you in advance for your help! Jordon So after a great deal of work I finally get my code working... Main hurdle was clearing the setTimeOut... A simple example: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-DE"> <head> <script type="text/javascript" src="js1.3.js"></script> <style> .windowcht { position:absolute; top:30%; width:150px; height:150px; right:50%; background:yellow; } </style> <script> $(function() { //mouse hover effects $('.windowcht').fadeTo('slow', 0.1); $('.windowcht').mouseenter(function() { $(this).fadeTo('fast', 1); }); $('.windowcht').mouseleave(function() { var hov = this; var timeout; timeout = setTimeout(function() { $(hov).fadeTo('slow', 0.1); }, 2000); $('.windowcht').mouseenter(function() { clearTimeout(timeout); }); }); }); </script> </head> <body> <div class="windowcht"> This is my text </div> </body> </html> I would love any suggestions for my code to be less resource hungrey, I mean pure js code, not jquery. Suggestion?? I need to know how to subtract a number which selecting an option from checkboxes. As seen in picture below. Basically you have a maximum of 10 stats to select. If you select say 3 Strength, I need the 10 to change to a 7, and it changes on each new value the select boxes have. So when they equal 10, it'd show a red 0 remaining. I'd prefer some way of not allowing more than a maximum of 10 from being selected, but don't know if thats even possible. Thanks for any help! Code: <h2>Starter Stats</h2> <ul> <li>You have <b>10</b> stats remaining.</li><br /> <li> <table width="75%"> <tr><td> <b>Focus</b></td><td><select name="focus"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></td></tr> <tr><td> <b>Attack</b></td><td><select name="attack"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></td></tr> <tr><td> <b>Defense</b></td><td><select name="defense"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></td></tr> <tr><td> <b>Dexterity</b></td><td><select name="dexterity"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></td></tr> <tr><td> <b>Magic Defense</b></td><td><select name="magicdefense"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></td></tr> </table> HI evey one I want to make a vote music web site , some thing like this : http://www.pmctop20.com/ we can drag each of the items in the left panel and drag it to the vote rows . How can I do so? It's a jquery script Thanks How could a make a html button that each time your press it it does a new things?
OMG, Check out the background on this site... http://paulirish.com/ how would I even start to rip that for use on my own site? I'll pay someone $15 on paypal if they can make a css and js file that I can just link too and have this background
when i try to run this it always says INPUT FROM A FILE. a file can have more than one birthday at it will be output also to a file. sorry for my bad english Code: import java.util.*; public class ZodiacSign { public static void main(String[] args) { String sign=""; String element=""; String chineseSign=""; int month, day,year; Scanner c = new Scanner (System.in); System.out.println("Enter day(1-31): "); day = c.nextInt(); System.out.println("Enter month(1-12): "); month = c.nextInt(); System.out.println("Enter year: "); year = c.nextInt(); if((month == 1) && (day <= 20) || (month == 12) && (day >= 22)) { sign = "Capricorn"; } else if((month == 1) || (month == 2) && (day <= 19)) { sign = "Aquarius"; } else if((month == 2) || (month == 3) && (day <= 20)) { sign = "Pisces"; } else if((month == 3) || (month == 4) && (day <= 19)) { sign = "Aries"; } else if((month == 4) || (month == 5) && (day <= 21)) { sign = "Taurus"; } else if((month == 5) || (month == 6) && (day <= 21)) { sign = "Gemini"; } else if((month == 6) || (month == 7) && (day <= 23)) { sign = "Cancer"; } else if((month == 7) || (month == 8) && (day <= 23)) { sign = "Leo"; } else if((month == 8) || (month == 9) && (day <= 23)) { sign = "Virgo"; } else if((month == 9) || (month == 10) && (day <= 23)) { sign = "Libra"; } else if((month == 10) || (month == 11) && (day <= 22)) { sign = "Scorpio"; } else if(month == 12) { sign = "Sagittarius"; } if((sign.equals("Aries"))||(sign.equals("Leo"))||(sign.equals("Sagittarius"))){ element="Fire"; } else if((sign.equals("Taurus"))||(sign.equals("Virgo"))||(sign.equals("Capricorn"))){ element="Earth"; } else if((sign.equals("Gemini"))||(sign.equals("Libra"))||(sign.equals("Aquarius"))){ element="Air"; } else if((sign.equals("Cancer"))||(sign.equals("Scorpio"))||(sign.equals("Pisces"))){ element="Water"; } int x = (1997 - year) % 12; if ((x == 1) || (x == -11)){ chineseSign="Rat"; } else{ if (x == 0){ chineseSign="Ox"; } else{ if ((x == 11) || (x == -1)){ chineseSign="Tiger"; } else{ if ((x == 10) || (x == -2)){ chineseSign="Rabbit"; } else{ if ((x == 9) || (x == -3)){ chineseSign="Dragon"; } else{ if ((x == 8) || (x == -4)){ chineseSign="Snake"; } else{ if ((x == 7) || (x == -5)){ chineseSign="Horse"; } else{ if ((x == 6) || (x == -6)){ chineseSign="Sheep"; } else{ if ((x == 5) || (x == -7)){ chineseSign="Monkey"; } else{ if ((x == 4) || (x == -8)){ chineseSign="Chicken"; } else{ if ((x == 3) || (x == -9)){ chineseSign="Dog"; } else{ if ((x == 2) || (x == -10)){ chineseSign="Pig"; } } } } } } } } } } } } System.out.println("Your Zodiac sign is "+sign+"."); System.out.println("Chinese Zodiac is: "+chineseSign+"."); System.out.println("Element is "+element+"."); } } How would I clean up this code? it looks so ugly, would I put it in a for loop and make it loop through and set the rand2, rand3, rand4 = place... there so there is a lot less lines of code(which is what I want) I need a cleaner way to do this, so it isn't so much space. Can someone help? there needs to be different variables because I need the random to be different for each, so rand2 = different random value than rand3. var place = [74,111,148,185,222,259,296,333,370]; var random = [rand,rand2,rand3,rand4,rand5,rand6,rand7,rand8,rand9]; var rand = place[Math.floor(Math.random()*place.length)]; var rand2 = place[Math.floor(Math.random()*place.length)]; var rand3 = place[Math.floor(Math.random()*place.length)]; var rand4 = place[Math.floor(Math.random()*place.length)]; var rand5 = place[Math.floor(Math.random()*place.length)]; var rand6 = place[Math.floor(Math.random()*place.length)]; var rand7 = place[Math.floor(Math.random()*place.length)]; var rand8 = place[Math.floor(Math.random()*place.length)]; var rand9 = place[Math.floor(Math.random()*place.length)]; var newrand = place[Math.floor(Math.random()*place.length)]; var newrand1 = place[Math.floor(Math.random()*place.length)]; var newrand2 = place[Math.floor(Math.random()*place.length)]; var newrand3 = place[Math.floor(Math.random()*place.length)]; var newrand4 = place[Math.floor(Math.random()*place.length)]; var newrand5 = place[Math.floor(Math.random()*place.length)]; var newrand6 = place[Math.floor(Math.random()*place.length)]; var newrand7 = place[Math.floor(Math.random()*place.length)]; var newrand8 = place[Math.floor(Math.random()*place.length)]; var newrand9 = place[Math.floor(Math.random()*place.length)]; var old = place[Math.floor(Math.random()*place.length)]; var old1 = place[Math.floor(Math.random()*place.length)]; var old2 = place[Math.floor(Math.random()*place.length)]; var old3 = place[Math.floor(Math.random()*place.length)]; var old4 = place[Math.floor(Math.random()*place.length)]; var old5 = place[Math.floor(Math.random()*place.length)]; var old6 = place[Math.floor(Math.random()*place.length)]; var old7 = place[Math.floor(Math.random()*place.length)]; var old8 = place[Math.floor(Math.random()*place.length)]; var old9 = place[Math.floor(Math.random()*place.length)]; So I am working on a project to take an integer that the user gives, and then get all the squares and cubes of all the numbers before that to the number given. It displays it in a text area. Maybe I am just lost for the moment, but It just prints the number that I give with the square root and cube instead of starting from 1, and ended on the integer I give. Code: var square_cube = function (){//This f var number = parseInt($("maxbase").value); for (var i=1;i <= number;i++) { var squ = Math.pow(i,2); } var j; for (j=1;j<=number;j++) { var cub = Math.pow(j,3); } var message = i-1 + " " +squ+ " " +cub; $("powers").value = message; } Hi - Im pretty new to all this! Have created a form on my website, uploaded database to server, but when the form is submitted - instead of opening the property selection, it just lists the Index of /home/properties and files within that folder. Can anyone help me please? Perky
Hi all, Can anyone point me in the right direction for some sample code that when the selection on a checkbox changes, either writes or removes some content? In this instance, when the checkbox is unchecked, I want more table rows and columns written with the relevant data within them. Then when checked, I want this data removed. Many thanks I have an AJAX search bar what searches after each keyup, but id like to make it so it runs the search if theres a certain delay after the keyup so if you search "hello" it doesnt run 5 times, only once (because there wont be a half a second gap between each letter. Sorry if that doesn't make sense >.<, im just curious if 1) thats possible, 2) what i need to look at to get this to work. Thanks Need help adding var target to this form action Would This be correct? var form = inp.form; form.target = "_self"; Code: <html> </head> <script type="text/javascript"> function formop(inp,op) { var form = inp.form; form.action = op + ".php"; var temp = inp.id.split(","); form.id.value = temp[0]; form.FirstName.value = temp[1]; form.LastName.value = temp[2]; } </script> </head> <body> <form method="post"> <input type="hidden" name="id"> <input type="hidden" name="FirstName"> <input type="hidden" name="LastName"> <input type='image' id='show,me,data' onclick=formop(this,'add'); src='static/icon16/add.jpg'> <input type='image' id='show,me,data' onclick=formop(this,'edit'); src='static/icon16/edit.jpg'> <input type='image' id='show,me,data' onclick=formop(this,'delete'); src='static/icon16/delete.jpg'> </form> </body> Hello guys, so i have a problem. i have a css/div box, and i have a login form. what im tryn to do is make it so that when i login, it it takes whats in the action of the form and shows it in the div box. the div box is like one of those cool popup boxes, it's done by using javascript and css. anyway, the div box works. the login form works. i just haven't been able to figure out how to get it to appear in the div instead of into a new page. so if any1 can help that would be much appreciated! here's my code: Code: <head><link rel="stylesheet" type="text/css" href="main.css" /> <link rel="stylesheet" type="text/css" href="popup.css" /></head> <form name="Login" method="post" action="login/check.php"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td>Username:</td> <td>Password:</td> </tr> <tr> <td><input name="myusername" type="text" class="txt" id="myusername"></td> <td><input name="mypassword" type="password" class="txt" id="mypassword"></td> <td><input type="submit" class="btn" name="Submit" value="Login" onmouseover='this.style.cursor="pointer" ' onfocus='this.blur();' onclick="document.getElementById('PopUp').style.display = 'block' "></td></tr> </table> </form> <div id='PopUp'> <br /> <div id="close"> <a id="link" onmouseover='this.style.cursor="pointer"' onfocus='this.blur();' onclick="document.getElementById('PopUp').style.display = 'none'"> <span id="span">Close</span></a> </div> </div> Thanks for all the help Old Pedant. You're nice enough to lend people a hand when you don't have to, and this makes the second or third time you've helped me solve a problem I've had with my website. Thanks so much. So I'm making a page where when someone clicks on the second drop list, then it carrys out a function first, and it calculates it based on what the first droplist is picked. Here's the code I have: Code: <html> <head> <title></title> <script type="text/javascript"> function first() { var gold = 4; var green = 6; var red = 30; var blue = 0; var total = 100; if (calculate.color.GetElementById('gold').select) { var depends = gold/total }; if (calculate.color.GetElementById('green').select) { var depends = green/total }; if (calculate.color.GetElementById('red').select) { var depends = red/total }; if (calculate.color.GetElementById('blue').select) { var depends = blue/total }; if (calculate.choice1.GetElementById('first').select) { calculate.results.value = 1 * calculate.howmany.value * depends; } } </script> </head> <body> <form name="calculate"> <table> <td> I need: <input type="text" name="howmany" /> <br /> My choice is: </td> <td> <select name="color"> <option selected id="gold">Gold</option> <option id="green">Green</option> <option id="red">Red</option> <option id="blue">Blue Charms</option> </select> <br /> <select name="choice1"> <option id="first" onClick="first()"> First </option> </select> </td> </tr> <tr> <td colspan="2" align="center" valign="top"> You will need <input type="text" name="results" /> </td> </tr> </table> </form> </body> </html> Any help is well appreciated. Thanks. OK I basically have a form field called prepend and if someone enters something in there I want it to prepend to my form action="" how can I insert anything into action ="" depending on what is entered I hope this makes sense. I AM SO LOST <script type="text/javascript"> function SearchGo(){ var searchField = document.getElementById("SearchInput"); var url = "http://url" document.location = url + encodeURIComponent(searchField.value); } </script> //field where URL will be entered and needs to be prepended <input type="text" name="prepend"> //form output is here <form name="searchform" target="_blank" action="";> <input type="button" value="Search" onClick="SearchGo();"/> Hi! I'm using NiftyPlayer (http://www.varal.org/niftyplayer/) to play an mp3 on my website. I'd like it to refresh the page when the song is over (I have some php grabbing songs from a database and choosing the one to play at random). NiftyPlayer has two functions that are probably useful for this. First, if you have a link go to: Code: javascript:alert(niftyplayer('niftyPlayer1').getState()) It will display the current state of the player (stopped, playing, paused, finished). Presumably, a piece of javascript could poll this variable every second, and once it equals "finished", execute the redirect. However, I think this other piece of code included with NiftyPlayer would help even more. In the .js file, it says the following: Code: this.registerEvent = function (eventName, action) { // eventName is a string with one of the following values: onPlay, onStop, onPause, onError, onSongOver, onBufferingComplete, onBufferingStarted // action is a string with the javascript code to run. // // example: niftyplayer('niftyPlayer1').registerEvent('onPlay', 'alert("playing!")'); this.obj.SetVariable(eventName, action); }; So it would appear that I could use something like this to automatically refresh when the song is over: Code: niftyplayer('niftyPlayer1').registerEvent('onSongOver', 'location.reload(true)'); The problem here is that I have no javascript experience and have no idea how to implement either of these ideas. Help? hi, I would like to pop up an edit window when I submit my form, my code below doesn't seem to work?! think my syntax is wrong soemwhere?! Code: function popUpBig(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=360,left = 220,top = 250');"); } <form method="post" name="times"><input type="hidden" name="day" value="Monday" /><a type="submit" class="button" onSubmit="javascript:popUpBig('edit_day.php')" ><span>Edit</span></a></form> Hi guys. I was wondering if its possible to switch a form action using javascript. Because im trying to have a search field on my main site for my forum and website. By having two boxes underneath my search field so people can select if the want to search my phpbb forum ore my site. Well anyway, mabey switching the form action is not the right approach. Any tips are welcome thanks. |