JavaScript - Help Needed - Number To %
Hi All,
Im a total novice with coding other than html/css. I have a video xml which, in which i need a new feature, could you help me with that? Basically my video is being entered with a time of it - for example 30sec. I have start and end trackers firing for the video but now i want to add impression trackers at 25%, 50%, 75%. I managed to do it using specifying seconds for the calls, but it becomes a pain to recalculate seconds for every video. Any ideas I could follow? Thanks, AD Similar TutorialsI have a function below where every time a question is submitted, it will add a new row in the table with a textbox which allows numbers entry only. My question is that I don't know how to code these features in this function: 1: I want the text box to be between 0 and 100, so if text box contains a number which is above 100, it will automatically change the number to the maximum number which is 100. Does any one know how to code this in my function below in javascript: Code: function insertQuestion(form) { var row = document.createElement("tr"); var cell, input; cell = document.createElement("td"); cell.className = "weight"; input = document.createElement("input"); input.name = "weight_" + qnum; input.onkeypress = "return isNumberKey(event)"; cell.appendChild(input); row.appendChild(cell); } I am trying to figure out how to make a random number I can plug into a script count down from that number at certain times of the day until it reaches 0. I would like it to reset itself at midnight every day. I'm trying to make it work with a script I found on here that resets itself at midnight every day. So instead of it counting down too fast, it would count down to the next number after a randomly generated number of minutes until it reaches 0. But it wouldn't necessarily have to end at 0 at midnight. It could go from 845 to 323 at the end of the day at a slower pace. Is that possible?
When I used toFixed() method on a number, I thought that this method round a number to a specified approximation, but I got a surprising result, the number became string! 15.23689 .toFixed ( 2 ) ==> "15.24" So does it convert the number into string? I am delving into the coding world and while I understand the basic principle of cookies, conditional statements, arrays, etc... I am still learning how to properly implement them. Any asistance with the following situation would be greatly appreciated and help with my learning as I try to reverse engineer the logic. I have looked around the web and this forum with little success. If the situation below is too complicated, I would really appreciate even a shove in the right direction regarding the logic. ----------------- How could I show a preset counter which counts up from a preset, beginning number toward a preset, end number? I imagine the increment and speed is set be the difference between the two numbers and a timeframe. Assumptions: I would rather not set the increment but edit the end number to show a steady increase. As I update that number, the increment adapts dynamically. I would want the number/script to be useful, so it should not refresh to the beginning number on each page load (i.e. num=0). When a visitor comes to the page, it must seem like the counter has been steadily been increasing in their absence. Coke or Pesi did something similar one time regarding cans sold to date (doubt it was plugged into a DB somewhere but rather based on a steady sales figure) and it was pretty cool. All the best! I can generate a random number between 1 and 9, ( var rand_no = Math.floor( 1 + Math.random() * 9 ); ) but I want to add that random number to a value that is enterred into an inputbox and get a total. How can I do this using Javascript and put the result into a hidden field. I will also need to use that same random number in another place on another form . Thanks I have a dynamic form that uses Code: var input_box = $("<input type=\"text\" id=\"ac\" >") I need to have a unique id for each input that is displayed. How can I do this? I can't use vars or anything in there as variables don't work in this as it is? Hi, I have a string stored in a variable var = "4.25 houses". I would like to only extract the currency value, ie "4.25" from this. Is this possible? Also I would like to divide and multiply the new variable I get... does this number need to be converted or something? Thanks in advance! This is quite easy yet hard. I'm trying to apply something in my forums, where a member could post something let's say: "Hi, I am number [random]1, 6[/random]" And what would happen is that, a number from 1 to 6 would be the content, for example, it would be: "Hi, I am number 3" But if you refresh the page, it would still be the same number. Like it won't be randomized again. So how do I make a javascript/html code that would make a one time number randomizer. Hi. I'm trying to make a web page using javascript for validation, but after the last 2 functions I wrote, 2 functions don't work anymore. I attached the file so you can see for yourself. And I know there are a few things I could do to the html, but I'm saving those for last. Any idea why the scripts don't work is much appreciated. (the functions that don't work a "cont_pag1" and "cont_pag2"...btw...they worked just fine until I wrote the last few functions (the ones for the pag4 div))...And sorry for the really strange language...
I need help on some code
Code: function makefarm(){ document.getElementById("farms").value ++ ; document.getElementById("pop").value -=2 ; document.getElementById("coin").value -=10 ; document.getElementById("lumber").value -=20 ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; document.getElementById("CIfarm").value ++ ; } function upgradefarm(){ document.getElementById("iron").value -=5 ; document.getElementById("coin").value -=20 ; document.getElementById("farmupgrades").value ++ ; } var food = function () { var f1 = document.getElementById('buttonhere'); var f2 = '<input type="button" value="Make Farm" onclick="makefarm()" /> Farms:<input type="text" id="farms" size="1" value=0 style="background-color:transparent;border:0px solid white;" READONLY/> <input type="button" value="Upgrade Farm" onclick="upgradefarm()" /> Farm Upgrades:<input type="text" id="farmupgrades" size="1" value=0 style="background-color:transparent;border:0px solid white;" READONLY/> <br/><br/><br/> Current Income:<input type="text" id="CIfarm" size="1" value=0 style="background-color:transparent;border:0px solid white;" READONLY/>'; f1.innerHTML = f2; } Code: Coin:<input type="text" id="coin" value=50 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> Lumber:<input type="text" id="lumber" value=100 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> Iron:<input type="text" id="iron" value=25 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> Food:<input type="text" id="food" value=100 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> POP:<input type="text" id="pop" value=10 size="1" style="background-color:transparent;border:0px solid white;" READONLY /> so if i press the makefarm() button it will add to the numbers but if i press it again they will got to zero how could i make it remember the numbers?(the input boxes are the second code) Ooook so this is probably the stupidest question ever. I know in java you can take advantage of a number being an int (not double) and divide by something without getting a remainder. But in javascript you dont declare what kind of variable something is. So my problem is: Given any double or triple digit number, how do i get all but the last digit. Like if i have 13, I need to make an int with 1. If it's 103 i need one with 10. Thanks!! Hello, I need to be able to get a number to 2dp without rounding e.g. 14.756 needs to be 14.75 I tried .toFixed(2) but this rounds. I thought of converting to a string and performing string functions but it seems like over kill if there is an easier way. thanks I need to write something like this: http://justsheri.com/webscripting/wsassignment/1049950/ If you look at the code there is 52 of these <img src = './images/blank1.png' onClick='clickCard("qh",0)'/> where clickcard("numchanges", increments by 1) how is this done? Thanks Danny Hi All, I have a problem in javascript. When i am doing rounding of the value i am getting the o/p like 2.2e4. I have to display this value in decimal value(2.0002) not in exponential. Can any one please help me to resolve this issue.? Regards, VIjai I am using a JavaScript price calculator. Right now it does everything I need except for one thing. If you look at the "type" field, they can choose either woven or printed. Right now, if they choose "woven" it adds 6 cents to to the total as you can see in this portion of the code: if (theForm.select.value=="woven") { priceeach+=0.06; Rather than 0.06, how do I get it to add a percentage--say 20% The form is located he http://goo.gl/YlJWo Thank you! Arrrgggghhhhhhhhh - help.... - LOL Now I've got that over with, hope someone can help. Am just learning regular expressions and am trying to validate UK format telephone numbers (have had an extensive look on the web and only examples I can find are US tests). Anyway, I want to learn to do it myself. UK phone number rules a Must start with a 0 in position 1 Next 2 to 4 characters must be a number Next character can be a space or a dash Next 6 to 9 characters can be a number, space or dash only Anyway, as I say, am new to regular expressions and trying to learn so I tried to write the expression to fit the rules above - see below: Code: ^[0]{1}\d{2,4}\s|-{1}\d|\s|-{6,9}$ My logic (for what it's worth - LOL) tells me this should work, but it doesn't - it accepts letters as well - which I really don't understand yet. Anyway - hope someone can help. Thanks Dominic Hello guys, this is my first post here, im a newbie in javascript and i need to limit a textbox to only be 1 or 0, I dont want to use a checkbox because i would like the users to really be typing. heres what i got: Code: <input name="test" type="text" onchange="validaten(this.value)" size="15" /> <script type="text/javascript"> function validaten(test) { if (test != 0); alert("Only 1 and 0 are allowed"); } </script> Can you please help me? Need Phone Number Validation for my JavaScript, i can't work it out It currently has E-mail, Surname, Address and Name validation, This is my code at the moment: Code: <script language="JavaScript"> function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Please Enter a Valid E-mail") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(dot,(lat+2))==-1){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(" ")!=-1){ alert("Please Enter a Valid E-mail") return false } return true } function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } function validate_form(thisform) { with (thisform) { if (validate_required(Name,"Name must be filled out!")==false) {Name.focus();return false;} if (validate_required(Surname,"Surname must be filled out!")==false) {Surname.focus();return false;} if (validate_required(Country,"Address must be filled out!")==false) {Country.focus();return false;} } { var emailID=document.submitting.email if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter a Valid E-mail") emailID.focus() return false } if (echeck(emailID.value)==false){ emailID.value="" emailID.focus() return false } return true } } function verifyEmail(form) { checkEmail = form.email.value if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) {alert("You have entered an invalid email address. Please try again."); form.email.select(); return false; } else { form.method="get"; form.rel="nofollow" target="_self"; form.action="myscript.cgi"; form.submit(); } } </script> Code: <form action="submit.htm" onsubmit="return validate_form(this)" method="post" name="submitting"> <span class="style5">Select Plant: <form id="form1" name="form1" method="post" action=""> <label> <select name="Item" id="Item"> <option>OMGwoopwoop Plant</option> <option>I'm Blue Plant </option> <option>Anonymous Plant</option> <option>Rawr Plant</option> <option>Chicka Plant </option> <option>Fruitopola Plant</option> <option>Whitoe Plant</option> <option>Wukidoo Plant </option> </select> </label> </p> <p>Name:<span class="style1"> <input type="text" name="Name" size="30"> <br> <br> </span>Surname: <span class="style1"> <input type="text" name="Surname" size="30"> <br> <br> </span>Address:<span class="style1"> <input type="text" name="Country" size="30"> <br> <br> </span>Email:<span class="style1"> <input type="text" name="email" size="30"> <br></span></p> Phone Number:<span class="style1"> <input type="text" name="phone" size="30"> <form action="submit.htm" onSubmit="return validate_form(this)" method="post"> <input type="submit" value="Submit"> </form> Is there a built in function to format a number to 2 decimal places and to add commas like below. 2,222.33 30,033.98 1,222,345,99 Hi all, I'm self learning JavaScript and this got me stumpped. I've wrote a very similar function that works perfect but no matter what i do here, the result is always the same. I can't seem to enter a 2 digit number in the second box for weight and therfore won't work. It seems to work fine for up to 9 lbs though. can anyone shed light to this? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script> //this array contains strings that can be broken down //into Shipping Zone, Shipping Range, Shipping Charges //This array is for origin zip 532xx. Weight max is 10lbs var PriorityMailArray = new Array("1 01 04.90", "2 01 04.90", "3 01 04.95", "4 01 05.05", "5 01 05.15", "6 01 05.25", "7 01 05.35", "8 01 05.55", "1 02 05.00", "2 02 05.00", "3 02 05.35", "4 02 05.95", "5 02 07.50", "6 02 08.10", "7 02 08.60", "8 02 09.55", "1 03 05.70", "2 03 05.70", "3 03 06.55", "4 03 07.50", "5 03 09.00", "6 03 09.95", "7 03 10.70", "8 03 12.70", "1 04 06.45", "2 04 06.45", "3 04 07.55", "4 04 08.60", "5 04 11.90", "6 04 13.00", "7 04 13.80", "8 04 15.30", "1 05 07.65", "2 05 07.65", "3 05 08.75", "4 05 09.85", "5 05 13.50", "6 05 14.85", "7 05 15.85", "8 05 17.65", "1 06 08.30", "2 06 08.30", "3 06 09.65", "4 06 11.00", "5 06 15.05", "6 06 16.65", "7 06 17.80", "8 06 19.90", "1 07 08.95", "2 07 08.95", "3 07 10.55", "4 07 11.75", "5 07 16.80", "6 07 18.40", "7 07 20.05", "8 07 22.40", "1 08 09.60", "2 08 09.60", "3 08 11.45", "4 08 13.30", "5 08 18.20", "6 08 20.20", "7 08 22.05", "8 08 25.10", "1 09 10.25", "2 09 10.25", "3 09 12.35", "4 09 14.40", "5 09 19.75", "6 09 22.00", "7 09 23.95", "8 09 27.95", "1 10 10.90", "2 10 10.90", "3 10 13.25", "4 10 15.70", "5 10 21.35", "6 10 23.75", "7 10 26.30", "8 10 30.40" ); //this function makes sure the user has entered zone and weight //and then goes through the array and finds the correct zone and weight that //fits into - then sets the value of the charges field //to the correct charge function FindCharges(){ var Zone = document.getElementById("Zone").value; var Weight = document.getElementById("Weight").value; var Charges = 0 if (Zone.length != 1) { alert("You must enter Shipping Zone!"); document.getElementById("Zone").focus();} if (Weight.length != 1) { alert("You must enter shipping weight!"); document.getElementById("Weight").focus(); return; } else{ Zone = parseFloat(Zone); Weight = parseFloat(Weight); } var curRangeStart, curRangeEnd, Zone, Weight, Charges; for (var i = 0; i < PriorityMailArray.length; i++) { curRangeStart = parseFloat(PriorityMailArray[i].substring(0, 1)); curRangeEnd = parseFloat(PriorityMailArray[i].substring(2, 4)); if (Zone == curRangeStart && Weight == curRangeEnd) { Charges = parseFloat(PriorityMailArray[i].substring(5, 10)); document.getElementById("Charges").value = Charges; return; } } alert("You entered in an invalid zone!"); document.getElementById("zone").focus(); } </script> </head> <body> Enter shipping zone and weight: <input type="text" id="Zone" size="1" onkeydown="document.getElementById('Zone').value=''"> <input type="text" id="Weight" size="5" onKeyDown="document.getElementById('Weight').value=''"> <input type="button" onclick="FindCharges()" value="Find Charges"> Shipping is: <input type="text" id="Charges" size="5" disabled> </body> </html> Thanks for the help |