Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

JavaScript help please

Thread Tools
 
Search this Thread
 
Old Jan 23, 2009 | 09:54 PM
  #1  
spufus's Avatar
spufus
Thread Starter
Scooby Regular
iTrader: (2)
 
Joined: Oct 2003
Posts: 661
Likes: 0
From: In the summerhouse
Default JavaScript help please

I've written this script to calculate the rough price to carpet a room.
Works fine in IE. It works if FF but instantly refreshes the form & clears the data.
Anyone any ideas?

Thanks in advance.

Code is below

<html>
<head>
<script type="text/javascript">

function roundTo4(raw)
{
strFloat = raw.toString();
var newFloat;

if(strFloat.indexOf(".") > 0 && strFloat.length - strFloat.indexOf(".") > 5)
{
strFloat = strFloat.substring(0,strFloat.indexOf(".") + 6);

var numFloat = parseFloat(strFloat);
var rndFloat = Math.round(numFloat * 10000);
var temp1Float = rndFloat / 10000;
var temp2Float = temp1Float.toString();

newFloat = temp2Float.substring(0,temp2Float.indexOf(".") + 5);
}
else
{
newFloat = strFloat;
}
return newFloat;
}

function roomCalc(form)
{
var p = form.p.value;
if(isNaN(p))
{
alert("Not a Number");
document.getElementById("p").value = "";
return false;
}

var w = form.w.value;
if(isNaN(w))
{
alert("Not a Number");
document.getElementById("w").value = "";
return false;
}

var l = form.l.value;
if(isNaN(l))
{
alert("Not a Number");
document.getElementById("l").value = "";
return false;
}

var volume = p * w * l;
var volumeOut = roundTo4(volume)
document.getElementById("bv").value = volumeOut;
}



</script>
</head>


<body>
<form>
<b>Room calculator</b><br />
<select id="p">
<option value="2">Karndean £2.00 sq metre</option>
<option value="2.5">Karndean £2.50 sq metre</option>
</select><br>

Room width (metres) approx: <input id="w" style="text-align:right"></input><br />
Room length (metres) approx: <input id="l" style="text-align:right"></input><br />
<button onclick="roomCalc(this.form)">Calculate</button><br>
Price: <input id="bv" style="text-align:right"></input>

</form>
</body>
</html>

Last edited by spufus; Jan 23, 2009 at 10:08 PM.
Reply
Old Jan 23, 2009 | 10:13 PM
  #2  
Dedrater's Avatar
Dedrater
Scooby Regular
 
Joined: May 2008
Posts: 3,957
Likes: 0
Default

It looks fine to me. Have you got the Runtime Environment plugin for FF? It will flash off if you havn't
Reply
Old Jan 23, 2009 | 10:15 PM
  #3  
Dedrater's Avatar
Dedrater
Scooby Regular
 
Joined: May 2008
Posts: 3,957
Likes: 0
Default

Could you post the calculation you are trying to achieve in base 10
Reply
Old Jan 23, 2009 | 10:47 PM
  #4  
spufus's Avatar
spufus
Thread Starter
Scooby Regular
iTrader: (2)
 
Joined: Oct 2003
Posts: 661
Likes: 0
From: In the summerhouse
Default

Here it is with the rounding function gone:

Simpler, but still upsetting FF


<html>
<head>
<script type="text/javascript">

function roomCalc(form)
{
var p = form.p.value;
if(isNaN(p))
{
alert("Not a Number");
document.getElementById("p").value = "";
return false;
}

var w = form.w.value;
if(isNaN(w))
{
alert("Not a Number");
document.getElementById("w").value = "";
return false;
}

var l = form.l.value;
if(isNaN(l))
{
alert("Not a Number");
document.getElementById("l").value = "";
return false;
}

var volume = p * w * l;
document.getElementById("bv").value = volume;
}

</script>
</head>


<body>
<form>
<b>Room calculator</b><br />
<select id="p">
<option value="2.00">Karndean £2.00 sq metre</option>
<option value="2.50">Karndean £2.50 sq metre</option>
</select><br>

Room width (metres) approx: <input id="w" style="text-align:right"></input><br />
Room length (metres) approx: <input id="l" style="text-align:right"></input><br />
<button onclick="roomCalc(this.form)">Calculate</button><br>
Price: <input id="bv" style="text-align:right"></input>

</form>
</body>
</html>
Reply
Old Jan 23, 2009 | 10:52 PM
  #5  
Dedrater's Avatar
Dedrater
Scooby Regular
 
Joined: May 2008
Posts: 3,957
Likes: 0
Default

Makes no sense to me unless you post off the math mate

I need to know what you are trying to achieve, base 10 to me would mean the actual function.

Last edited by Dedrater; Jan 23, 2009 at 10:54 PM.
Reply
Old Jan 23, 2009 | 10:55 PM
  #6  
Dedrater's Avatar
Dedrater
Scooby Regular
 
Joined: May 2008
Posts: 3,957
Likes: 0
Default

Sorry, I don't know what you want to achieve?

Is that the whole program?

Last edited by Dedrater; Jan 23, 2009 at 10:57 PM.
Reply
Old Jan 23, 2009 | 10:59 PM
  #7  
Dedrater's Avatar
Dedrater
Scooby Regular
 
Joined: May 2008
Posts: 3,957
Likes: 0
Default

[QUOTE=Dedrater;8450451]
I need to know what you are trying to achieve,
Reply
Old Jan 23, 2009 | 11:03 PM
  #8  
spufus's Avatar
spufus
Thread Starter
Scooby Regular
iTrader: (2)
 
Joined: Oct 2003
Posts: 661
Likes: 0
From: In the summerhouse
Default

Originally Posted by Dedrater
Sorry, I don't know what you want to achieve?

Is that the whole program?
Yes,

It calculates a rough cost to carpet a room. Carpet cost per metre in drop down * room width in text field * room length in text field.

The function works in IE & FF but in FF all fields are cleared for some reason.

Needs some more thought methinks....
Reply
Old Jan 23, 2009 | 11:26 PM
  #9  
Dedrater's Avatar
Dedrater
Scooby Regular
 
Joined: May 2008
Posts: 3,957
Likes: 0
Default

Karndean? is that a type of flooring/carpet?

anyway

Firefox is slimline on addons, what about Google's CHROME browser?
Reply
Old Jan 23, 2009 | 11:32 PM
  #10  
Dedrater's Avatar
Dedrater
Scooby Regular
 
Joined: May 2008
Posts: 3,957
Likes: 0
Default

I do understand btw


Last edited by Dedrater; Jan 23, 2009 at 11:36 PM.
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
StickyMicky
Computer & Technology Related
3
May 22, 2004 03:02 PM
CodeKey@Lisan
Computer & Technology Related
11
Feb 20, 2004 05:23 PM
RichB
Computer & Technology Related
2
Nov 5, 2003 02:27 PM




All times are GMT +1. The time now is 02:40 AM.