I have the following calculation (simplified to focus on the point):
Code:
var scroll_percentage = scroll_button_distance/scroll_wrapper_width;
or imagine this is:
Code:
var scroll_percentage = 100/500;
The answer is -INFINITY
How do I make this into a usable number?I searched for INFINITY and found plenty of info but am not sure how to simply get the "0.2" answer I need for the next calculations.
I'm using this plugin:I was wondering if anybody knew of a way to place a percent mask on one input field that can have the possibility to be in both of these formats..
field <input type="text" id="interest_rate" /> mask
function update(value1){ doAjax("behind_scan.php" , "id="+value1); }function doAjax(url , str ){ xmlhttp=GetXmlHttpObject(); if (xmlhttp==null){ alert ("Browser does not support HTTP Request"); return; }url=url+"?"+str; xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); }function stateChanged(){ if (xmlhttp.readyState==4){ //document.getElementById("txtHint").innerHTML=xmlhttp.responseText; //alert(xmlhttp.responseText) document.forms.myform.scanner.value = ""; document.forms.myform.scanner.focus(); }}function GetXmlHttpObject(){ if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); }if (window.ActiveXObject){ // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; }
This pages calls a function on a separate php page to run 2 mySQL queries, the value must be put in the text 3 times in quick succession before the database is altered. I've tried all the other functions and they seem to be fine, AJAX is my weakness but I need it for the main functionality of my website. I need this to work.
I have 2 things going on here. One, the 'percent' variable is constantly showing up as NaN (not a number) no matter what numbers I give it. I suspect it is happening because the function is populating all the fields at one, which causes a 'divide by zero' scenario for the percentage field, which is last in line. Which brings me to my send thing. How to write this function correctly, as it obviously is causing problems as is, and it seems clunky. I think it should broken up into a couple different functions, but I tried that and NOTHING worked.
Here is the code, let me kow what you think: function calculate(){ var contractsAdded = document.forms[0].contractsAdded.value; var priceAdded = document.forms[0].priceAdded.value; var contractsSold = document.forms[0].contractsSold.value; var priceSold = document.forms[0].priceSold.value; var totalAdded = (contractsAdded * priceAdded) * 100; var totalSold = (contractsSold * priceSold) * 100; var gainLoss = totalSold - totalAdded; var percent = gainLoss / totalAdded;
right now im using a percent bar to redirect the page when all buttons are clicked but i want a more efficient way of doing the redirect there will be a total number of buttons on my page, for examply 5 every time one is clicked, is there a possible way of subtracting 1 and when buttons = 0 the page redirects
I have 3 textbox controls on my web page that are numeric currency fields in which a user can enter a numeric value, either positive or negative into TB1 and TB2 (both of these fields go thru edit checks to make sure a numeric value is entered and then return a currency value ie; $2500.00). TB3 is calculated resulting in TB3 = TB1 (($6500)) - TB2 ($2500).
My problem is that if a user enters a negative value for TB1, it returns a "NaN" and the value in TB3 turns out to be the same value as in TB2. Essentialy the calulation ends up being 0 - 2500 = 2500 (see screenshot). I've attached 2 functions below.
Code: function cal_Overage_Shortage() { if (make2Number("TB_LowPoint") <= 0) { document.getElementById("TB_OverageShortage").value = GetValueTextbox("TB_LowPoint") + GetValueTextbox("TB_RequestedLowPoint");
I occasionally need to set a negative margin on objects for positioning but 1.6.x ignores the declarations. This use to work fine with earlier versions. Has this issue been addressed? I tried all the combinations I could think of and the setting is ignored if a value is negative. (did not find a problem reference when setting a negative value in the forums)
If a negative number is entered into the reading variable it should be displayed as a zero. This works with the first calculations such as average but right at they very end the the alert wont display the highest average it just displays the one which has a negative number typed in to it.
I have a calculated value that is negative, which I need to display in a javacript prompt as positive. In ColdFusion, there is a function called ABS(), which gives you the absolute value of the number in question, so ABS(-5) = 5. Is there something similar in javascript? If no, how would I display a negative number without it's negative sign? Again, this is only for display purposes withing an alert.
I'm just starting out learning and have sort of given myself a couple of basic problems to solve. I pretty quickly found something that's apparently hard to Google.I've made a page that shows a counter number, starting at 0, with buttons that will increase or decrease the number by 1 or 10.So I'd like to figure out how to show that number in red when it is a negative number and in green when it is a positive number. I've tried a couple of things, including an if... else, but here's my latest crack:
var counter=0; function countUp() { lastCounter=counter;
I've been trying to figure this out for hours. I want to write a js so that if the number in the 2nd column is negative, then the javascript changes the css color to red, so that the number is red. If the number is positive, then make it green. Do I need an array or loop, I just can't get anywhere.
I have a function that does some calculations and populates some text fields with the results. I also have a function that changes the font color of the numbers to red if they are less than zero. What I dont have is a way to make them work together. I imagine I need to pass the results of the calculation function to the change color function, but not sure how to go about doing that. Here is the calculation function:
function to calculate the total costs, gain/loss and return percent. function calculate() {
I have a problem in asp application validation. My textbox only accepts numeric value.It should not accept empty field and negative values and charcters.I am not aware of IsNan function.
Is there a way in a regexp to *not* match a fixed string value?
Using [^blah] gives matches to anything not containing *any* of letters b,l,a and h. Whereas I want to match anything that does not containing the exact string 'blah', i.e. *all* the letters.
Hello everyone... I've got a question about an onKeyUp event. I'm using a text box that HAS to be a negative number therefore it has to have a - sign in front of the number. Can someone point me in the right direction as to how to write a function to do this? Thanks so much...
I cant get my cookie to work. I believe its not my javascript that is wrong. Can anyone take a look to see what i did wrong in my cookie? I have to pages dropdown1.html and dropdown2.html. Both pages have the same exact dropdown list. There is also a javascript file called script.js which makes it so you get an error if you select the same option on the second drop down list as the first. Also in the script.js i have a cookie that should run so dropdown2.html should now what was selected in dropdown1.html Can anyone see if i made a mistake in either my javascript code in my cookie? Right now I am not getting the error message if you select the same option as the first. Ill show all my code incase you need it for reference
dropdown1.html
Code:
Code:
Script.js (this is the part where I cant figure out why the error message does not appear on the second dropdown menu if user selects the same option as the first)
I have a problem, I don't know why this code doesn't work on IE ver 8 On Firefox, Chrome it is like I want, on IE - no reaction Is this some html/css problem or my fault on js? I'm sure about .js code is correct.. I think.. link html/css/js
this will not work on change. also the innerhtml wont display. please help. here is the js:
function checkemail(){ if (document.suform.email.value && document.suform.emailcheck.value) { if (document.suform.email.value == document.suform.emailcheck.value)
can i use x on top of cbe versions prior to 5? will this cause any conflicts and break anything? is there anything i need to be aware of or watch out for?
After the user types in the textboxes and press enter (with the cursor still in one of the textboxes), buttonXXX should be pressed by default.(the user is too lazy to take the cursor over to buttonXXX and click).
The problem is the top/left most button (button A) gets pressed which annoys them to death. So I tried to do this.
In the bottonA's onfocus event handle- document.forms[0].elements['buttonXXX'].focus() .
Result: ButtonXXX receives focus alright, but the code for buttonA still executes!
The following passes the test as valid, and the mouseover for the six indicated areas also work. I need various areas to link to another page, including the six mentioned. However either the MAP works by itself, or the below mouseover works, but not both. Code:
The last time I tried to ask this question...Google Groups screwed up my message and there was no subject (sorry for that - I know it's annoying).
I'm trying to learn how to develop a plug-in that allows users to display data from one site in a third party site, like Google Adwords or the Digg counter for news stories. I took a look at Digg.com and found the following:
It looks like digg is doing the following to show the number of "diggs" for a story on your website. On my page I would have the following:
I did a clean install of Windows XP on my computer and my javascript will not work. I've tried all types of browsers, I've download the Service pack 1 for XP and IE. I have download java from Sun, which I know is not javascript but it could not hurt. I have done everything I know of to fix this problem but still Javscript will not work on my windows XP. I don't know where to turn from here, Microsoft surely does not have any info about on their website....
I've written some kind of menu to display a diagram with input fields for a budget plan. A user should be able to change values, which are initially filled by a database value, and get all corresponding values filled by the program.
//value given by database showText[k].setAttribute("value", eval("liste[i][TEXT" + k + "]"));
//onchange event for the user to change the value showText[k].setAttribute("onchange", "calculate('cost" + i + "')");
//function to recalculate corresponding values function calculate(myId) { if (myId == "initial") { ... } else { myId = myId.slice(4); //getParents(myId) returns corresponding values for myId var myParents = getParents(myId); for (var i = deep; i >= 0; i--) { var sum = 0; for (var j = 0; j < myParents.length; j++) { ... for (var k = 0; k < children.length; k++) { sum += parseFloat(document.getElementById(eval("'cost" + children[k] + "'")).getAttribute("value")); }}}}}}
My Problem is: IE and Netscape always use the value initially entered by the database and not the new value entered by the user. Is there a timing or DOM problem?