Comparing Decimal Numbers
Jul 31, 2010I am trouble in comparing decimal number.
var1 = 0.25
var2 = 0.50
if (var1<var2)
{
alert("Value is less than minimum")
[CODE]....
How can I make it work.
I am trouble in comparing decimal number.
var1 = 0.25
var2 = 0.50
if (var1<var2)
{
alert("Value is less than minimum")
[CODE]....
How can I make it work.
This sci calculator listed in [URL] has Round function which rounds the result to a nearest integer. I wonder if it possible to easy modify it so that it would leave two numbers after decimal point when it perform rounding? The calculator's script has these codes related to Round:
<INPUT style="WIDTH: 74px; HEIGHT: 31px" onclick="Round()" type=button size=24 value=Round>
And
function Round()
{form1.display.value=Math.round(form1.display.value);}
I tried {form1.display.value=Math.round(form1.display.value,2);}, but it did no do it.
I am currently using a function to validate a form on the client side
(see code below). At the end of the function, I would like it to also
compare a startDate against an endDate to ensure that the endDate is
greater than (comes after) the startDate. The date format I'm using is
MM/DD/YYYY and it's writing to an MS SQL Server 2000 database table
via ASP. Code:
I have two strings that I need to compare and modify when there is a
matching value in the two. If strA = ??,' then I need to remove
the value ??,' from strB and the new value would be strB =
??,12935'
strA = ??,'
strB = ??,12937,12935' (these could be any values in any order)
I'm not sure where to begin on this.
I need to check if two hashes are identical.
My thoughts are something like this:
function compareHash(hash1,hash2){
if(hash1.length != hash2.length){return false}
for(var key in hash1){
if(hash1[key] != hash2[key]) return false;
}
return true;
}
Have I missed something, or is there a more direct approach?
I'm having trouble comparing 2 input boxes, using getElementById.
I have 81 hidden inputs (id's b0 through b80) and 81 input boxes (id's a0-a80). (Its just sudoku, so theres no security threat with them being viewable in the source)
I'm using this code (ill worry about the for loop later)
var solved = true;
if(document.getElementById(a0).value != document.getElementById(b0).value) {
solved = false
alert("not solved"); // debug
}
But it doesnt seem to be working. Im getting the error a0 is not defined. I know for sure that I have an input box with id=a0.
I need to test the contents of three fields to validate which contain text, and based on the results, set additional variables. I'm sure this is falling off the log simple, and I got it to work in PHP, but am having problems getting the syntax correct in Javascript.
In a nutshell, if a front AND a rear msg is entered, the price is $115, else the price is $80. I'm sure there's an easier way to code this than what I've done, but I don't know how to correctly perform several && and || in the same comparison.
Here's the PHP...
function notEmpty(){
var FrontMsgTxtTop = document.getElementById('FrontMsgTxtTop').value;
var FrontMsgTxtBottom = document.getElementById('FrontMsgTxtBottom').value;
var RearMsgTxt = document.getElementById('RearMsgTxt').value;
[Code]....
i'm looking for a way to check if the name of the page is equal to a link inside the page being checked. for instance:inside the address bar: http://www.mysite.test.html
<body>
<ul>
<li><a href="test.html"></a></li>
[code]....
I have the following script
function timeDifference(laterdate,earlierdate) {
var difference = laterdate.getTime() - earlierdate.getTime();
var daysDifference = Math.floor(difference/1000/60/60/24);
difference -= daysDifference*1000*60*60*24
document.write('difference = ' + daysDifference + ' day/s ');
}
var laterdate = ?;
var earlierdate = ?;
timeDifference(laterdate,earlierdate);
//--></script>
And would like to insert my datein and dateout values where the ? marks are above in red. I can call these variables into the form on the page using <%=Request("datein")%> but how do I call a variable into the script above?
I am developing a battleship game in javascript. I created a table of grid squares pictures. In the tags in included onclick = "a specific method to place a ship(this.id). This is not working. I am wondering if there is an easier way to pass an id through a parameter or would I have to do something different?
View 1 Replies View RelatedI have a material table wich contains the article number, a quantity input field, a max quantity field... How can i test that the input quantity is less than the max quant one ?
Here is a sample code :
I need to modify the script showed at: [URL]
Right now it allows entering "numbers only", I need it so that it allows numbers and alphabets only, no special characters or spaces.
And yes, one more question, does the first part of the code need to be added in the <head> of the document or <body> ?
The code at the above URL is as follows:
<script type="text/javascript">
// initialise variable to save cc input string
var cc_number_saved = "";
</script>
[Code].....
I have this function which works great in Firefox, but doesn't work in IE. I can make it work in IE by breaking it in Firefox, but I'd like it to work in both.
Here's the function, with associated code:
function validate_check(input, message)
{
var par = input.parentNode;
var prev = input.previousSibling;
if(!input.checked) {
if(prev.innerHTML != message) {
var errmsg = document.createElement("p");
errmsg.innerHTML = message;
par.insertBefore(errmsg, input);
}
dosubmit = false;
} else if(prev.innerHTML == message) {
par.removeChild(prev);
}}
var agree = document.getElementById('agree');
var agreemsg = 'Please make sure you agree to our <a href="/tou.php" target="_blank">Terms of Use</a> and <a href="/privacy.php" target="_blank">Privacy Policy</a> to add your listing.'
validate_check(agree, agreemsg);
For the two attributes the function accepts, input is a node from that document tree that is a checkbox, and message is a string.
If the checkbox is not checked the function inserts a <p> element immediately before the input. That part works fine in both. However, the 'prev.innerHTML == message' and 'prev.innerHTML != message' don't work properly in IE. I think it is because of the <a> tags in 'message'. However, when I try to use the String() function there are problems because the 'prev' object is not always set, (like, if a paragraph isn't written right before the checkbox).
I want to put a form on my site where the user can enter some information, but I don't want the user to enter the same information twice over the couple of fields that I have.
Is there a javascript that can help to validate the form information or some other way? And if so, is it easy to do?
i want an argument that will ask if the previous xmlhttp content was = to the current xmlhttp content. Like as so:
Code:
if(oldxmlhttp = xmlhttp) {
alert("yes");
} else {
[Code]....
All in all i want to make it so it doesn't reload if content is not different. To hold control over the server.
How do I go about comparing two jquery objects to see if they're actually the same html object.
I've got:
This should add a border to every object in the selected set except for the one defined in someobject... shouldn't it.
I have a pair of dates in a form that are made up of 3 text fields per date. The day and month fields are 2 digit, the year is 4 digit.
startday
startmonth
startyear
endday
endmonth
endyear
I can't easily change this for a number of reasons. I know the values themselves will be valid (they're generated by a calendar selection script) but I want to check the date created by the end variables is not before the start date. Any script to build a date from the 3 fields for each, and return false if the end date is earlier than the start date?
I'm looking to do two things: the first is to move elements of an array to the next index using a function. I have managed to do this like so:
var letters = ['h','i','j','k'];
function moveElements(anArray){
var newArray = anArray;
[code]....
I have 2 fields in a form, field1 is type hidden while field2 is type text.Both will have numbers in them. I need to compare these 2 in my form validation and having issues getting it to work right. If I do something similar to the following:if ((passForm.field1.value) < (passForm.field2.value) ) {alert.....It runs, but is running the validation, but is reading the values as text and literally left to right.
so for example
If field1 = 12 and field2=3 it does not run the alert (wrong)
If field1 = 12 and field2=100 it runs the alert (wrong)
[code]....
I'm trying to make my form both check that the e-mail's match and also be case insensitive when being submitted. I've figured out how to get the e-mail's to be checked to match, but can't figure out how to also make it not case sensitive.
This is what I have so far...
<head>
<script type = "text/javascript">
function checkSame() {
var emval1 = document.cform.email.value;
[Code]....
I am using the following function in order to change an image opacity on a mouseover and mouseout. This function works fine but does not handle a onClick. What I mean by this is...... How can I create/alter the function to handle an onclick? I want to be able to click on an image (one of many) and have that image opacity change to 50%. There are other similar images whose opacity would need to remain at 100%. If one of those are clicked, that images opacity would then change, and the previous would restore to original value of 100% I thought about passing the clicked images id to the function but I can't find a way to compare an image id VS a passed image id.
[Code]...
Can anyone make a textbox have an ATM style decimal? You know as you type the decimal stays put for example it starts with 0.00 then if keypress 1 is shows 0.01 then if keypress 2 is shows 0.12 and so on. Get it?
View 12 Replies View RelatedCan anyone please help/direct me to find/write a simple Javascript function to clean up a decimal point or a coma on a number.
For Example I need
10.000 to become 10000
or
10,000 to become 10000
I'm gradually changing the color of some list items like this, but since i is decimal, I'm not getting the full Hex range. Is there a simple way to change i to Hex, so I go from 0 to F? Does jQuery have a function to do that?
jQuery('li').each(function(i){jQuery(this).css('color','#'+i+'0f')});
I am having an issue with converting my decimal to a percentage. Below is my code:
(cost * .06) is where the issue is
var cost = prompt("What is the cost of your purchase?", "")
document.write("Return Value: "+cost,("<br />"));
var salestax = cost * .06
document.write("Return Value: "+salestax,("<br />"));
var total = cost + salestax
document.write(cost + salestax);
If I get a percentage result on a form, for example: 95.44186046511628
Is there a way I can limit it to only 2 decimal places like 95.44? It won't always be 95.44186046511628, so it just wouldn't apply to just that one percentage. I need it to only have 2 decimal places with whatever the value is.