Handling Maths In Strange Way?

Aug 25, 2010

I have javascript calculating the total price of all the products in a shoppping cart. The prices are in the format of 10.99 or 5.50 or 10 ete.g if there are five items bought for 10.99 and 1 bought for 10, the script will multiply 10.99 by 3, then multiply 10 by one, then add the two results.

The resulting number is sometimes right, but quite often it ads an extra '000000002' or so to the amount??

[Code]...

View 3 Replies


ADVERTISEMENT

Maths Game

Oct 3, 2003

Have a look at this maths game I made. It tests you on adding, subtracting, multiplying and dividing and has three different levels.

Note-you must save the code below as mathsgamefinal.htm for the reset button to work.


<html>



<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<meta http-equiv="Content-Language" content="en-gb">

<title></title>

</head>



<body bgcolor="#FF0000">



<script type="text/javascript">



function next1(){

var outof=document.getElementById('outof').value;

if(document.getElementById('next').value=="Next" && document.getElementById('type').value=="a"){document.getElementById('next').value='Enter' add(); document.getElementById('answer').value='answer'}
else if(document.getElementById('next').value=="Next" && document.getElementById('type').value=="m"){document.getElementById('next').value='Enter' times(); document.getElementById('answer').value='answer'}
else if(document.getElementById('next').value=="Next" && document.getElementById('type').value=="t"){document.getElementById('next').value='Enter' minus(); document.getElementById('answer').value='answer'}
else if(document.getElementById('next').value=="Next" && document.getElementById('type').value=="d"){document.getElementById('next').value='Enter' divide(); document.getElementById('answer').value='answer'}

else if(document.getElementById('next').value=="Enter" && document.getElementById('answer').value==(cr)){ document.getElementById('question').value='Correct' document.getElementById('next').value='Next' document.getElementById('outof').value=parseInt(document.getElementById('outof').value)+1; document.getElementById('score').value=parseInt(document.getElementById('score').value)+1; pc();}

else{ document.getElementById('question').value='Wrong. Answer= '+cr; document.getElementById('next').value='Next' document.getElementById('outof').value=parseInt(document.getElementById('outof').value)+1; pc();}

document.getElementById('answer').select();
}



function add(){
ea1=(Math.floor(Math.random() * (1 - 10)) + 10);
ea2=(Math.floor(Math.random() * (1 - 10)) + 10);
ma1=(Math.floor(Math.random() * (21 - 49)) + 49);
ma2=(Math.floor(Math.random() * (21 - 49)) + 49);
ha1=(Math.floor(Math.random() * (111 - 299)) + 299);
ha2=(Math.floor(Math.random() * (111 - 299)) + 299);

if(document.getElementById('level').value=="e"){document.getElementById('question').value=ea1+' plus '+ea2; cr=ea1+ea2}
if(document.getElementById('level').value=="m"){document.getElementById('question').value=ma1+' plus '+ma2; cr=ma1+ma2}
if(document.getElementById('level').value=="h"){document.getElementById('question').value=ha1+' plus '+ha2; cr=ha1+ha2}
}
function times(){
em1=(Math.floor(Math.random() * (2 - 10)) + 10);
em2=(Math.floor(Math.random() * (2 - 10)) + 10);
mm1=(Math.floor(Math.random() * (11 - 19)) + 19);
mm2=(Math.floor(Math.random() * (6 - 12)) + 12);
hm1=(Math.floor(Math.random() * (21 - 29)) + 29);
hm2=(Math.floor(Math.random() * (21 - 29)) + 29);

if(document.getElementById('level').value=="e"){document.getElementById('question').value=em1+' times '+em2; cr=em1*em2}
if(document.getElementById('level').value=="m"){document.getElementById('question').value=mm1+' times '+mm2; cr=mm1*mm2}
if(document.getElementById('level').value=="h"){document.getElementById('question').value=hm1+' times '+hm2; cr=hm1*hm2}


}

function minus(){
et1=(Math.floor(Math.random() * (10 - 20)) + 20);
et2=(Math.floor(Math.random() * (1 - 10)) + 10);
mt1=(Math.floor(Math.random() * (50 - 99)) + 99);
mt2=(Math.floor(Math.random() * (20 - 50)) + 50);
ht1=(Math.floor(Math.random() * (350 - 1000)) + 1000);
ht2=(Math.floor(Math.random() * (350 - 1000)) + 1000);

if(document.getElementById('level').value=="e"){document.getElementById('question').value=et1+' minus '+et2; cr=et1-et2}
if(document.getElementById('level').value=="m"){document.getElementById('question').value=mt1+' minus '+mt2; cr=mt1-mt2}
if(document.getElementById('level').value=="h"){document.getElementById('question').value=ht1+' minus '+ht2; cr=ht1-ht2}


}
function divide(){
ed1=(Math.floor(Math.random() * (2 - 10)) + 10);
ed2=(Math.floor(Math.random() * (2 - 10)) + 10);
md1=(Math.floor(Math.random() * (11 - 19)) + 19);
md2=(Math.floor(Math.random() * (11 - 19)) + 19);
hd1=(Math.floor(Math.random() * (21 - 29)) + 29);
hd2=(Math.floor(Math.random() * (21 - 29)) + 29);
ed3=ed1*ed2;
md3=md1*md2;
hd3=hd1*hd2;

if(document.getElementById('level').value=="e"){document.getElementById('question').value=ed3+' divided by '+ed2; cr=ed1}
if(document.getElementById('level').value=="m"){document.getElementById('question').value=md3+' divided by '+md2; cr=md1}
if(document.getElementById('level').value=="h"){document.getElementById('question').value=hd3+' divided by '+hd2; cr=hd1}
}


function answerreset(){
if(document.getElementById('answer').value=="answer"){document.getElementById('answer').value=''}
}

function pc(){
document.getElementById('scorepercent').value=document.getElementById('score').value/document.getElementById('outof').value*100;
document.getElementById('scorepercent').value=Math.round(document.getElementById('scorepercent').val ue);
}
</script>

<table border="0" width="198" height="180" bordercolor="#000000" style="background-color: #FFFF00; border-style: solid">

<tr>

<td height="33" width="99" colspan="2">

<p align="center">

<select size="1" name="type" id='type'>

<option value="a" selected>Add</option>

<option value="t">Take away</option>

<option value="m">Multiply</option>

<option value="d">Divide</option>

</select></p>

</td>

<td height="36" width="99" colspan="2">

<p align="center">

<select size="1" name="level" id=level>

<option value="e" selected>Easy</option>

<option value="m">Medium</option>

<option value="h">Hard</option>

</select></p>

</td>

</tr>

<tr>

<td height="36" width="198" colspan="4">

<p align="left">

<input type="button" name="T1" id='question' value="Click next to begin" style="background-color: #FFFF00; border: 0 solid #FFFF00">

</p>

</td>

</tr>

<tr>

<td height="33" width="66">

<p align="center"><input type="text" name="answer" size="6" id='answer' onclick=answerreset()></td>

<td height="36" width="66" colspan="2">

<p align="center"><button onclick='next1()' id='next'>Next</button></td>

<td height="33" width="66">

<p align="center"><button onclick='window.location="mathsgamefinal.htm"'>Reset</button></td>

</tr>

<tr>

<td height="36" width="66">

<p align="center">Score %:</td>

<td height="33" width="66" colspan="2">

<p align="center">Score Marks:</td>

<td height="33" width="66">

<p align="center">Out of:</td>

</tr>

<tr>

<td height="33" width="66">

<p align="center"><input type="button" name="T1" size="3" id=scorepercent value="0"></td>

<td height="33" width="66" colspan="2">

<p align="center"><input type="button" name="score" size="3" id=score value="0"></td>

<td height="36" width="66">

<p align="center"><input type="button" name="outof" size="3" id=outof value="0"></td>

</tr>
</table>
</body>
</html>



Any feedback would be much apprieciated...

View 6 Replies View Related

Maths - Squaring Variables

Oct 26, 2006

I have a variable which I'm dividing ..

var ltotal = (data/12)

I now need to sqaure this, and also cube it after that ..

Not sure at all how to square and then cube this result, seperately .. can anyone give me some pointers?

View 9 Replies View Related

Maths Using Randomly Selected Symbols?

May 12, 2010

I am randomly selecting the maths symbol (+,-,*,/) using a math.random and then applying the relevant symbol to a variable based on the result, ie if result == 1 then symbolGen = "+"

I now need to use this symbol in the Javascript for it's original purpose, as I have two other numbers being generated and need to work out the answer.

View 4 Replies View Related

Strange Encoding

Jul 23, 2005

It's the first time I read the following code.
A few js files like the one below, but I don't know how to make them
readable by a human ( me ).

Is it a strange character set ? an obfuscation ? both ?
Firefox or IE detects no errors, so the following code is run with no
problem.

View 4 Replies View Related

Base64 Strange

May 14, 2007

I'm trying to send a byte array (JPG image) from javascript to a servlet for processing. I'm using Base64 to encode the byte array in javascript, and then a base64 decoder in the servlet to decode it.

The thing is, that even though the String has the same length on both sides, the decoded byte array is shorter then the original one. I've tried a couple of different implementation on both sides, with the same results.

View 4 Replies View Related

Strange Behaviour

Mar 17, 2006

Dont know how to put this. In my application i had one jsp where i did some modifications in the java script function and increased the maxlength of a field.

Just these two major modifications i did.But strangely everything got screwed up the function is not being called and many other java scripts func are not being called. Many buttons are not behaving strangely. That jsp is a very big one and a part of a major colossal application so i am not pasting it.

View 1 Replies View Related

Strange Firefox And IE Work

Dec 26, 2006

I have the following algorithm

1. Show message DIV

2. Long Loop Function

3. Hide message DIV

Opera shows DIV well. Firefox and IE don't show the DIV.
If to rewrite the algorithm like this Firefox and IE will show DIV

1. setTimeout(Long Loop Function,500)
2. Show message DIV

I also tried to debug the first algorithm in Firebug, and in step by
step mode I see that Firefox shows the DIVs.

Is it standart behaviour? What prevents browsers from showing the DIV?

View 1 Replies View Related

Strange 403 Error With New Window

May 17, 2006

I've used the following simple javascript in a link to open a new window:

<a href="javascript:void(0)" onclick="window.open('images/tshirtback.jpg','TShirtBack','width=540,height=660')">

This works and does as intended in all browsers other than (you've guessed it) MS IE wherby a 403 Forbidden error is generated. Anyone got any idea why this is the case and how I can get around it?

View 2 Replies View Related

Escape() Behaves Strange Sometimes

May 12, 2007

Yesterday I discovered a problem on one of my sites: escape function was encoding the same string Salò in two different ways:Sal%F2Sal%C3%B2
This was happening on Firefox 2.0.0.3. In Opera 9.20 was encoded ok every time.

So, in Firefox was a russian roulette . Sometimes was encoding the string like I wanted to, sometimes not. As a solution I use encodeURIComponent(), but the behavior of escape() seems strange to me.

View 7 Replies View Related

Check Checkbox Strange Problem

Dec 27, 2006

I have a program that creates dinamically a web page. In the page I have the following function to check how many checkbox are checked.

function tarInfo(info) {
var i=0;
var c=0;
var l=document.forms[0].selected_files.length;
alert(l);
for (i=0; i<document.forms[0].selected_files.length;i++) {
if (document.forms[0].selected_files[i].checked) {
c++
}
}
..
..

The problem is that if I have only one checkbox, the alert(l) write
undefined. If I have more than 2 checkbox, the function works well.
Here a part of the webpage with one checkbox.

<form name="form1" action="filemanager" method="POST"
enctype="multipart/form-data" >
..
..
<td>
<input type="checkbox" value="pbsrun.o100"
name="selected_files">
</td>
..
..
<input type="submit" class="button" name="tar" value="Tar"
tarInfo('tar')">

Where is the problem?

View 9 Replies View Related

Strange Behavior When Changing Select's Value

Jul 20, 2005

I expect to see "foo" for the 2nd alert. Instead, the value of select is
cleared. Am I missing something?

<html>
<head><title>Foo</title>
<script language="javascript">
<!--
function foo()
{
alert('Before change: ' + document.control.titleFont.value);
document.control.titleFont.value = 'foo'
alert('After change: ' + document.control.titleFont.value);
}
-->
</script>
</head>
<body>
<form name="control" method="POST">
<select name="titleFont">
<option value="sans-serif">Arial</option>
<option value="serif">Times</option>
</select>&nbsp;
<input type="submit" name="control" value="Submit" onclick="return
foo()"/>
</form>
</body>
</html>

View 1 Replies View Related

Strange Results When Submittng Form / Fix It?

Sep 14, 2009

I have a form that is submitted via jquery into a mysql database using php code...

View 1 Replies View Related

Strange Behaviour In Window.prompt()?

Dec 6, 2010

I have been working with with window.promt() and i noticed a weird behaviour.In some cases (i do not known why) my prompt cannot get over a certain limit of characters. But in some other cases it can get as many characters as i want.

View 7 Replies View Related

Strange Thing Happening With Onunload And Google

Jul 23, 2005

I have set up a disclaimer page for our public access PCs at our Libraries which has the following function:

function breach() {
alert("Proceeding beyond these Conditions is..................... If you have read the Conditions, scroll to the bottom and press the 'Yes I

agree' button.")
window.location="disclaim.htm"

and then in the body tag I have onunload=breach()
This works fine for all websites entered into the address bar except if

you enter www.google.com

What it is supposed to do is bring up the prompt and when you click on the OK button it will go back to the disclaimer page. They should only be able to get to the web by clicking on the 'Yes I
agree' button at the bottom of the disclaimer page. Does anyone out there know why google doesn't fire up the disclaim.htm page like all the other sites? It is very frustrating.

View 1 Replies View Related

JQuery :: Strange Incomplete Page Loaded?

May 18, 2011

We use WebSphere 6.1 as web server and the project is in ear file. After deployment, sometimes access server, the page was load incomplete, such as logo image (.gif) disappeared, and JavaScript error appeared. But after press on Refresh button from browser (IE), the page is loaded completed, all images are loaded and the JavaScript is gone.

[Code]...

We have tried to optimize the JSP page, however the page loaded is faster but this issue still occurred once in a while. Does anyone encounter the same issue before?

View 2 Replies View Related

JQuery :: Get A Strange Error Called:00ce56e?

Feb 4, 2010

This is a support ticket, stating the fact if that IE not support the characte encoding or somehow misinterprets the encoding you will get a strange javascript error called:00ce56e.This will apply on all your ajax transfers for one.For example i had a text/html;charset=utf8 header returned from a php-webservice i wrote. Nice i though, charencoding is the "plant-shit" (Crank quote) and code along and thought to myself, "Damn i'm a witty one". until i started the "IE" beast.. the beast throw out all my claims and the lookout for actually winning this went down. Until i found the above URL.. That is some crackhed shit right there. (Crank anyone?!).What it's stating more or less is that if IE 7 or 8 (or any program that uses whatever that is located in what dll) would more or less shit its pants when it run over an unspported encoding.. In this case UTF-8..

Ok, i'm a swedish guy and uses windows iso latin craptastic charsets more or less everyday but when coding for internationally webpages that are targeting multiple countries you cant get to be staring blindly at your own chars by altering my header to a text/html instead of a text/html;charset=utf8 response to my ajax script i solved alot of strange error shit. (but not my previous post with the fact that IE dont succed even if it would want to, thats a total other question but related but not directly if you get my drift.)..

View 1 Replies View Related

Strange Unterminated String Literal Error

Dec 22, 2007

I can't find anything wrong with this code <!-- Initialise the editor --><script>
initRTE('<table align="" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr></tr></tbody></table>', 'example.css');
</script>

However this throws an error in firebug and the page doesn't display it correctly, i get an error in firebug

unterminated string literal
initRTE('<table align="" border="0" cellpadding="0" cellspacing="0" widt...
Does anyone have and idea whats going on?

View 16 Replies View Related

Strange Border Appears In Js Image Flip

Jul 3, 2003

I'm creating a tabbed menu navigation for a site. I'm using javascript to to give the tabs a mouseover effect. I also have a function that decides whether the tab has been selected or deselected by the user, and uses that info to determine which image file to use in the img swap.

The page works fine in IE 6, however in Netscape 6.2, when I mouseover the tabs, a thin border quickly flashes around each image as it swaps. It looks like the placeholder that's displayed for a broken image in IE, only with only the border and no red "x". I'm not sure why this is happening, as all the images have been preloaded.

The markup is XHTML 1.0 Transitional. Here's the js I'm using:

View 1 Replies View Related

Strange Result In Adding Floating Elements Together?

Jun 17, 2011

I have a multidimensional array with the following:

Code:
IngList[0] = ['info','info',12.002,number,number];
IngList[1] = ['info','info',14.04,number,number];

[code].....

View 1 Replies View Related

JQuery :: Malsup Corners - Strange Top Nudges In IE6 And Opera

Sep 21, 2009

I am playing with malsup's corners and I am getting strange nudges on both top corners in Opera, IE6 and Konquerer when applied to nested elements (to achieve a cornered border). I am using exactly the same code as on the demo page: "$(this).corner("round 8px").parent().css ('padding', '4px').corner("round 10px")". Strangely this only appears when the radius is more than 10px and
div.outer's padding is less than 3px. All corners are rounded, just at the top div.outer still seems to have little develish horns.

View 2 Replies View Related

Strange Behaviour In Internet Explorer With Document.links[i].href

Jul 20, 2005

I have to change dynamically all hyperlinks, when the html-page is
loaded at the client. This works fine, except in the following scenario:

When the innerText of an anchor contains an '@', the InternetExplorer
changes the innerText-Property to the HREF-Property. I have checked this
with MoZilla/FireBird and Opera and there is no problem!

To explain, what i mean, see following example:
function atTest(){
for(var i=0; i < document.links.length; ++i)
{
document.links[i].href = document.links[i].href;
}

}

Now you need some anchor tags - notice the '@' as inner Text:

<a href="http://www.somelink.org/">Text before @ and after</a><br>
<a href="http://www.somelink.org/">Text before @</a><br>
<a href="http://www.somelink.org/">@ before text</a><br>
<a href="http://www.somelink.org/">Text before at and after</a>


If you load the page, InternetExplorer will display the HREF-Property
instead of "Text before @ and after" - all other elements are shown
correctly! It doesn't bother other browsers: Opera/MoZilla shows _even_
the first element with innerText.

My system: Windows XP SP1, InternetExplorer SP1, Firebird0.7, Opera 7.23

Has anybody out there an idea, why IE behaves like this? And how I can
work around this?

View 2 Replies View Related

JQuery :: Special Character Appearing In Combobox As Strange Symbol

Apr 15, 2010

I have here a jquery code that load one combobox to another with data from mysql. The point is, the combobox that receive the data from mysql, if I have a name with special character like "~" or "^" any other accent in the mysql, the combobox that receive this data appear a strange symbol like as in the file attached in the place of the letter that is with accent. The code that I have here is

$(document).ready(function(){ $("select[name=Empresas]").change(function(){
$("select[name=Unidades]").html('<option value="0">Carregando...</option>');
$.post("unidades.php",
{Empresas:$(this).val()},
function(valor){
$("select[name=Unidades]").html("<option>Selecione...</option>" + valor);
})})})

View 1 Replies View Related

Jquery :: Scrolling Floating Pane Works Strange In Case?

Oct 6, 2011

i tried to ad a bit of jquery to a pane in webpage under: [URL]... problem: the scrolling of the division does not stop at the bottom of the page, or, only chrome: at opening of the page, the division scrolls automatic to bottom of the page. the code is very little:

[Code]...

View 2 Replies View Related

Frame Handling

Jul 23, 2005

I'm looking for tutorials or articles considering HTML Frames and how to
handle them with Javascript.

E.g. samples how Frames can exchange information, can a Frame instruct
other Frame to update it's content etc.

View 5 Replies View Related

Date Handling

Oct 25, 2005

We have some date fields in our HTML forms in various places. In the
accounts package we use, there is some pretty nifty date handling.

It has a standardised date format of dd/mm/yyyy and if you enter e.g.

3-12 it will switch it to 3/12/2005

Same applies for e.g. 3:12 etc

Anyone know of some javascript which will do this for our HTML form
fields? Our target format is actually dd-mon-yyyy and it would make it
really nice for users if the system could accept a variety of input
formats and then switch it to a date to our specification. Any
suggestions?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved