Preventing A Negative Number - Should Be Displayed As A Zero
Nov 7, 2011
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.
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 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 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() {
If I had a webpage that displayed a database in tabular form, it would be nice to know how many lines of text the browser could display without scrolling, then have the cgi script output the appropriate number of lines of data to fill the screen.
I've seen examples of how to get the browser window size in pixels, but is there a way to determine the number of lines that are displayed?
I'm currently working on a javascript form validator and have run into a problem. The validator is used to make sure that the customer has entered a number in the quantity input box of the item they wish to purchase.
Code:
function validateRE(fieldToCheck, strRegExp, msg, min, max) { if (!min) { min = 0 } if (!max) { max = 100 }
for (i=0;i<15;i++) { if (fieldToCheck[i].value) { var re_pattern = strRegExp; if (!re_pattern.test(fieldToCheck[i].value) || fieldToCheck[i].value.length < min || fieldToCheck[i].value.length > max) { alert(msg); fieldToCheck[i].focus(); fieldToCheck[i].select(); return false; } } } return true; } Used with:
validateRE(this.quantity, /^[1-9]{1}$|^[0-9]{2,3}$/, 'Please enter a Quantity.', 1, 3)
);"> The part in question is the red highlighted section. The number of items that is under a specific product is generated dynamically and can range from 2-20. How can I get javascript to count the total number of items and run "for i=0;i<total number" instead so it is different for each product page?
I'm currently usingMalsup's Cycle plugin. I am just wondering is it possible to have cycle plugin return the index number of the currently displayed slide? I want to change the content of the page when a specific slide is active. Don't know how to achieve that..
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 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 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)
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 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.
I have a Java GUI application where I perform a lot of long DB operations [e.g. massive SQL Insert's], which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and clicks again, which created duplicate records.
So I am trying to disable the button as soon as it is clicked, and as soon as it's done, re-enable it again.
I tried to do it in Javascript, just simple: <input... name=Save... onclick="enabled=true;"> and as soon as screen refreshes, it re-enables the button automatically.
That works in some cases, however when I need to do some other Javascript operation (e.g. validate() the fields on the screen), disabling the button automatically stops both Javascript and association form action in Java which is totally unacceptable.
Is there any other simple solution to such problems in Java or Javascript?
Instead of searching and replacing unwanted character in strings using cgi/perl, I would like to prevent some characters from ever being typed in text boxes and textfields. Two characters I would like to stop are "|" (pipe symbol) and the "carriage return". I am not even sure how to search and/or replace a carriage return in a string anyway. This may be a JavaScript function, because what I would really like to do is send an alert to tell the user that it is not allowed.
I have an <input> box and i want to disable the apostrophe ( ' ) key, so when you press it, no character appears in the input box. All other keys should work ok.
I can trap the keypress event using "onkeypress=myKeypressHandler()" but, beyond that, I'm stuck. I forget how to detect what key was pressed or how to "null it out".
I'm using IE6 and users will be IE5.0 upward ONLY (trust me on this, suffice to say it's not a website but an intranet application).
I need to html encode all text field values on the client just before sending them to the server. A javascript equilalent of Server.HTMLEncode in IIS. I also need to be able to perform the reverse.
All I am trying to do is ensure that if a user enters html tags in the a form, that the tags does not get parsed by the browser.
I have a colour picker on my site, see it at [URL]Now I want to change the colour of the links on the page, don't worry I know how to do all this.
It's just if someone chooses full black (#000000) the theme looks awesome, but the links on the dark background are invisible.
Similarly if someone chooses full white (#ffffff) then you can't see the text on the white background.
So I want to know if you geniuses can make it so when a variable containing a hex, like #000000 is set as the main colour, then the link colour is changed to #666666 so you can still see it, but I want it to work with colours, so if you had #360000 (dark red) then the link colour would be something like #a10000.
I hope I have explained it well enough for you to understand, here is my code to change the background:
I'm trapping the onKeyPress event of a textarea, and I'm wondering if there's a way to prevent the key from also being typed into the textarea if it's a certain key. I have tried stripping off the last character from the value property, but it seems that the character is added after the event handler finishes.Here's my code, in case it helps:
I am trying to make a popup window with Javascript that will let a user choose either a Yes or No button and then be sent to a page after that.I really do not want this popup to be resizable. I have read that is not really possible in current browsers, but that you can prevent it form happening with resizeTo().I am not sure I'm doing this right though:
<input type='button' value="DELETE GROUP" onclick="javascript:Popup('deleteGroupWarning.html')" /> var stile = "top=10, left=10, width=300, height=300 status=no, menubar=no, toolbar=no
I have some code that gets executed in a document onload event. I display an alert message box saying that some action was performed successfully.
However the following annoying issue is bothering me. Whenever someone bookmarks the page, or go back to it, or even refreshes it, then the onload event gets fired again and the alert box appears.
Is there a safe way to make sure that the code in onload will get executed only once? and that cosecutive triggering of the page will not trigger any code execution.
The most important thing to note, is that I pass a parameter in the URL indicating that the code should be triggered in the onload event.
Obviously when I refresh the screen, the parameter is passed again and the code gets executed..
I'm using image as a resizing grip for my element and under IE and Opera it works fine but in Firefox it starts dragging the image when you press mouse button and move mouse and doesn't generate mousemove events. Is there a way to prevent the image from being dragged?
Ok I made a post yesterday for a calculations script and I figured it out.Now the problem I have is as soon as I put it on my website a competitor is going to steal the code and put it on his/her/their page.Is there a way that I can put in my html a call to the javascript so that it just gets the script runs it and then displays it to my page without actually having the source displayable anywhere? Here is the code I made that I want to protect: