Web Design and Development Forums

Javascript calculator help with coding

This is a discussion on "Javascript calculator help with coding" within the JavaScript Forum section. This forum, and the thread "Javascript calculator help with coding are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old May 1st, 2008, 14:48   #1 (permalink)
New Member
 
Join Date: May 2008
Location: London
Age: 33
Posts: 1
Javascript calculator help with coding

I would be grateful if someone could help me with some coding as I am quite a newbie when it comes to Javascript although I am learning.

I have some coding which produces a specific caluclator.

You enter numeric, length, width and height values and specifiy whether these measurements are in cm's or in inches. I have defined a formula with set parameters so that depending on what you enter, the caluclator with return a statement saying whether your item will fit into the box for example.

I have also made the boxes where you enter the values, turn red or green so that they visually indicate whther the item is too big / or will fit into the box.

There is one final piece of functionality I want to add. Under the 'Calculate - will it fit box' I want to add another function so that it tells you/calculates how many boxes yoou will require in total.

You will need to enter additional values for the 'total' VOLUME which would be Length, Width, Height and specify alike before whether the measurements are cm or in inches.

The formula I want to use is:-

total volume of object / 2.472cu.ft or 0.07 cu.m

You would then hit a button and the answer would be something along the lines of Approx Number of boxes required are ??? - the number would be presented here.

My current coding for the first part of the calculator as it stands is as follows:-

Grateful for any help!!!!!

Code: Select all
 <form name = "myform">
<p>Enter the length of your object: - <input type = "text" name = "lgth" size = "3" maxlength = "3" onKeyUp="checkNumeric(this)"></p>
<p>Enter the width of your object:&nbsp - <input type = "text" name = "width" size = "3" maxlength = "3" onKeyUp="checkNumeric(this)"></p>
<p>Enter the height of your object: - <input type = "text" name = "height" size = "3" maxlength = "3" onKeyUp="checkNumeric(this)"></p>
<p>These dimensions are in:</p>
<p> <input type = "radio" name = "rad1" value = "in" checked = "true"> Inches</p>
<p> <input type = "radio" name = "rad1" value = "cm"> Centimeters</p>
<p> <input type = "button" value = "Calculate - will it fit?" onclick="calculate()" ></p>
<p id="Message" > </p>

<input type="reset" value="Reset" onClick="return Reset();">

<script type = "text/javascript">

function Reset(){
var responce=confirm('Are you sure you want to clear all your entries? ');
if (responce){
var frm=document.myform
frm.lgth.style.backgroundColor='#FFFFFF';
frm.width.style.backgroundColor='#FFFFFF';
frm.height.style.backgroundColor='#FFFFFF';
document.getElementById('Message').innerHTML='';
}

return responce;
}

function calculate() {
var frm=document.myform
var cf = 1; // conversion factor

if (frm.rad1[0].checked) {
cf = 0.3937; // inches in one cm
}
var mess=[];
frm.lgth.style.backgroundColor='#FF0000';
if (frm.lgth.value == 0) {
mess.push("You must enter the length of your object");
}
else if (frm.lgth.value > 58*cf) {
mess.push("Your object is too long");
}
else {
frm.lgth.style.backgroundColor='#00FF00';
}
frm.width.style.backgroundColor='#FF0000';
if (frm.width.value == 0) {
mess.push("You must enter the width of your object");
}
else if (frm.width.value > 36*cf) {
mess.push("Your object is too wide");
}
else {
frm.width.style.backgroundColor='#00FF00';
}

frm.height.style.backgroundColor='#FF0000';
if (frm.height.value == 0) {
mess.push("You must enter the height of your object");
}
else if (frm.height.value > 31*cf) {
mess.push("Your object is too high");
}
else {
frm.height.style.backgroundColor='#00FF00';
}
if (mess.length>0){
document.getElementById('Message').innerHTML=mess.join('<br>');
return false;
}
document.getElementById('Message').innerHTML=("<b>Your object will fit into the Box (VCB)</b>");
return true;
}

function checkNumeric(which) {
if (/\D/.test(which.value)) {
alert ("Only numbers are valid!");
which.value = which.value.slice(0, -1); // remove invalid character
return false;
}
}

</script>
</body>

</html>

Last edited by aso186; May 1st, 2008 at 18:16.
Cat2008 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
For all Javascript Coding Experts, can you break down this code? BlackReef JavaScript Forum 12 Dec 10th, 2007 01:04
Help me,,Javascript coding toin JavaScript Forum 0 Apr 19th, 2007 04:14
Popup calculator masonbarge PHP Forum 1 Apr 19th, 2007 02:08
keypad calculator pelachrum JavaScript Forum 1 Aug 8th, 2005 22:26
calculator through link? pelachrum HTML Forum 1 Aug 6th, 2005 08:26



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 19:07.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59