Measurement Conversion - Java?
- hassonmike
- Lieutenant (LT)
- Posts: 76
- Joined: Tue Apr 19, 2011 2:13 pm
- Contact:
Measurement Conversion - Java?
Hello all, I am wondering if anyone has any advice on how I might be able to add a measurement calculator/converter to my website. Is something that can be done with java? or are there better ideas out there? Anything that might send me in the right direction would be very helpful.
Thanks!
Mike
Thanks!
Mike
Re: Measurement Conversion - Java?
I would probably use javascript instead of java, though java is certainly capable of creating a calculator.
http://www.w3schools.com/js/default.asp
This is a link to W3 School's javascript tutorial.
How is the calculator going to be used? Is it for the end-user to use or is it for measurement conversions in the code?
http://www.w3schools.com/js/default.asp
This is a link to W3 School's javascript tutorial.
How is the calculator going to be used? Is it for the end-user to use or is it for measurement conversions in the code?
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Measurement Conversion - Java?
I'm not sure this is the same way you want it implemented,but we customized one for a website that sells material by the square foot.
http://www.walldecorsuperstore.com/MT10 ... C1124.aspx
(We didn't do the site design.)
If you are interested, you could contact asoave@web2market.com for a quote.
http://www.walldecorsuperstore.com/MT10 ... C1124.aspx
(We didn't do the site design.)
If you are interested, you could contact asoave@web2market.com for a quote.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
- hassonmike
- Lieutenant (LT)
- Posts: 76
- Joined: Tue Apr 19, 2011 2:13 pm
- Contact:
Re: Measurement Conversion - Java?
So i found a copy/paste code for the exact purpose that i am looking for from
http://www.javascriptkit.com/script/scr ... rter.shtml
It is working fine in dreamweaver, but when it goes live on my site, the calculations do nothing. I can see everything in the drop down menus, but when i click the "to" button, nothing happens.
All of the code specified has been inserted into the aspx section, referenced to as [[ConLib:custom/ShipLengthCalc]]
I have added head and body tags to this aspx page as to follow the instructions for pasting the code, but it does not function, it functions fine when im testing it in dreamweaver, but once it goes live, it does nothing. I have no idea what might cause this
I got the following errors from chrome when activating any of the calculation functions. I'm wondering if anyone here can help me decipher these
1. Uncaught TypeError: Cannot read property 'from_unit' of undefined
1. convert_unitDefault.aspx:459
2. (anonymous function)Default.aspx:482
3. onchangeDefault.aspx:483
1. Default.aspx:459Uncaught TypeError: Cannot read property 'from_unit' of undefined
1. convert_unitDefault.aspx:459
2. (anonymous function)Default.aspx:496
3. onchangeDefault.aspx:497
1. Default.aspx:459Uncaught TypeError: Cannot read property 'from_unit' of undefined
1. convert_unitDefault.aspx:459
2. (anonymous function)Default.aspx:516
3. onclickDefault.aspx:517
Also, further testing shows that when this is active on my site, users in IE are unable to add items to their carts, for this reason It is not live for you to see for yourself, buut any ideas that might send me in the right direction with this would be very helpful
http://www.javascriptkit.com/script/scr ... rter.shtml
It is working fine in dreamweaver, but when it goes live on my site, the calculations do nothing. I can see everything in the drop down menus, but when i click the "to" button, nothing happens.
All of the code specified has been inserted into the aspx section, referenced to as [[ConLib:custom/ShipLengthCalc]]
I have added head and body tags to this aspx page as to follow the instructions for pasting the code, but it does not function, it functions fine when im testing it in dreamweaver, but once it goes live, it does nothing. I have no idea what might cause this
I got the following errors from chrome when activating any of the calculation functions. I'm wondering if anyone here can help me decipher these
1. Uncaught TypeError: Cannot read property 'from_unit' of undefined
1. convert_unitDefault.aspx:459
2. (anonymous function)Default.aspx:482
3. onchangeDefault.aspx:483
1. Default.aspx:459Uncaught TypeError: Cannot read property 'from_unit' of undefined
1. convert_unitDefault.aspx:459
2. (anonymous function)Default.aspx:496
3. onchangeDefault.aspx:497
1. Default.aspx:459Uncaught TypeError: Cannot read property 'from_unit' of undefined
1. convert_unitDefault.aspx:459
2. (anonymous function)Default.aspx:516
3. onclickDefault.aspx:517
Also, further testing shows that when this is active on my site, users in IE are unable to add items to their carts, for this reason It is not live for you to see for yourself, buut any ideas that might send me in the right direction with this would be very helpful
Re: Measurement Conversion - Java?
I think you are putting the code in the wrong place. Try putting it into the scriptlet the page is running instead of an aspx control. If you open a scriptlet in DreamWeaver, there should be a block at the top that looks like this (taken from the Home Page scriptlet):
If you edit a scriptlets header section from the AbleCommerce admin, this section is added, but you can also just add it yourself:
Put your javascript between the <HeaderData> tags. Put your HTML in the main (uncommented) part of the scriptlet.
You can also put a link to your javascript in the <HeaderData>.
I think you could also put the HTML parts into a ConLib control if you wanted to, but I don't know about the javascript, I've always just linked to it in the <HeaderData>.
This is what the top of my "Standard Header" scriptlet looks like:
Code: Select all
<!--
<Description>
Content to display on the home page of the website.
</Description>
-->
Code: Select all
<HeaderData>
[whatever you type into the box]
</HeaderData>
-->
You can also put a link to your javascript in the <HeaderData>.
I think you could also put the HTML parts into a ConLib control if you wanted to, but I don't know about the javascript, I've always just linked to it in the <HeaderData>.
This is what the top of my "Standard Header" scriptlet looks like:
Code: Select all
<!--
<Description>
Displays the standard store header.
</Description>
<HeaderData>
<script type="text/javascript" src="https://www.google.com/jsapi?[removed]"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="/App_Themes/BarknPurr/nav-help.js"></script>
</HeaderData>
-->
[all of my html for the scriptlet]
Re: Measurement Conversion - Java?
You can also use http://www.jslint.com/ to validate your javascript.
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Measurement Conversion - Java?
On pages where there will be a postback, you will probably have to write the javascript/jquery from the code behind so that the values will be retained.
That is what I had to do for this calculator.
That is what I had to do for this calculator.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
- hassonmike
- Lieutenant (LT)
- Posts: 76
- Joined: Tue Apr 19, 2011 2:13 pm
- Contact:
Re: Measurement Conversion - Java?
Thank you both. I placed the code into the scriptlet as mouse suggested, and it no longer interferes with the shopping cart functions, but the calculator still not function when it goes live (it does in dreamweaver when im testing) So there must be something interfering with it? But im not sure where to start looking, if there is a workaround, or otherwise how to proceed.
Judy, Would a currency changer drop down be a postback? and what do you mean by "write the javascript/jquery from the code behind so that the values will be retained"? Is this why mine doesnt function?
This is the code that I have for my sidebar (with the length calculator present, working in dreamweaver, but not on my site)
Is it something here that needs to be changed?
Judy, Would a currency changer drop down be a postback? and what do you mean by "write the javascript/jquery from the code behind so that the values will be retained"? Is this why mine doesnt function?
This is the code that I have for my sidebar (with the length calculator present, working in dreamweaver, but not on my site)
Code: Select all
<HeaderData>
<script type="text/javascript">
// Length Converter script- By Bruce Zhang
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// Please keep this notice intact
var factors1 = new Array(1, 0.01, 0.00001, 0.00000621, 0.3937, 0.0328, 0.01094);
var factors2 = new Array(100, 1, 0.001, 0.000621, 39.37, 3.28, 1.094);
var factors3 = new Array(100000, 1000, 1, 0.621, 39370, 3280, 1094);
var factors4 = new Array(160934, 1609.34, 1.60934, 1, 63360, 5280,1760);
var factors5 = new Array(2.54, 0.0254, 0.0000254, 0.0000158, 1, 0.08333, 0.02778);
var factors6 = new Array(30.48, 0.3048, 0.0003048, 0.0001896, 12, 1, 0.3333);
var factors7 = new Array(91.44, 0.9144, 0.0009144, 0.0005688, 36, 3, 1);
var factors = new Array(factors1,factors2,factors3,factors4,factors5,factors6,factors7);
function convert_unit()
{
from_index = document.length_con.from_unit.selectedIndex;
to_index = document.length_con.to_unit.selectedIndex;
factor = factors[from_index][to_index];
document.getElementById("formula").innerHTML = document.length_con.from_unit.options[document.length_con.from_unit.selectedIndex].text + " = " + factor + " " + document.length_con.to_unit.options[document.length_con.to_unit.selectedIndex].text;
if(isNaN(document.length_con.from_value.value))
document.getElementById("to_value").innerHTML = "Not a valid number.";
else
document.getElementById("to_value").innerHTML = factor * document.length_con.from_value.value;
}
</script>
</HeaderData>
<!--
<Description>
Displays a mini basket and a list of recently viewed products.
</Description>
-->
<p align="center"><h3 align="center">Choose Currency</h3></p><div align="center"> [[ConLib:custom/UserCurrencyMenuDropDown]]</div>
<p><br/>
[[ConLib:custom/HeaderBasketTotal]]
[[ConLib:custom/ShippingRates]]
</p>
<p>[[ConLib:custom/MiniBasket]] </p>
<p>[[ConLib:custom/RecentlyViewed Visible="false"]]
</p>
<h2>Length Converter</h2>
<form name="length_con">
<table>
<tr>
<td>From </td>
<td>
<select name=from_unit onChange="convert_unit()";>
<option> centimeters
<option> meters
<option> kilometers
<option> miles
<option> inches
<option> feet
<option> yards
</select>
</td></tr>
<td> To </td>
<td>
<select name=to_unit onChange="convert_unit()";>
<option> centimeters
<option> meters
<option> kilometers
<option> miles
<option> inches
<option> feet
<option> yards
</select>
</td>
</tr>
<tr>
<td> </td><td colspan="3"><div id="formula">centimeters = 1 centimeters</div></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td>Enter </td>
<td><input type="text" name="from_value" value="1" size="12" maxlength="12"></td>
</tr><td> <input type=button value="To" onClick="convert_unit()";> </td>
<td><div id="to_value">1</div></td>
</tr>
</table>
</form>
Re: Measurement Conversion - Java?
Try this. I re-arranged <Description> and <HeaderData> to be like AC would make it. I don't know if it will work any better, but its what caught my eye.
Code: Select all
<!--
<Description>
Displays a mini basket and a list of recently viewed products.
</Description>
<HeaderData>
<script type="text/javascript">
// Length Converter script- By Bruce Zhang
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// Please keep this notice intact
var factors1 = new Array(1, 0.01, 0.00001, 0.00000621, 0.3937, 0.0328, 0.01094);
var factors2 = new Array(100, 1, 0.001, 0.000621, 39.37, 3.28, 1.094);
var factors3 = new Array(100000, 1000, 1, 0.621, 39370, 3280, 1094);
var factors4 = new Array(160934, 1609.34, 1.60934, 1, 63360, 5280,1760);
var factors5 = new Array(2.54, 0.0254, 0.0000254, 0.0000158, 1, 0.08333, 0.02778);
var factors6 = new Array(30.48, 0.3048, 0.0003048, 0.0001896, 12, 1, 0.3333);
var factors7 = new Array(91.44, 0.9144, 0.0009144, 0.0005688, 36, 3, 1);
var factors = new Array(factors1,factors2,factors3,factors4,factors5,factors6,factors7);
function convert_unit()
{
from_index = document.length_con.from_unit.selectedIndex;
to_index = document.length_con.to_unit.selectedIndex;
factor = factors[from_index][to_index];
document.getElementById("formula").innerHTML = document.length_con.from_unit.options[document.length_con.from_unit.selectedIndex].text + " = " + factor + " " + document.length_con.to_unit.options[document.length_con.to_unit.selectedIndex].text;
if(isNaN(document.length_con.from_value.value))
document.getElementById("to_value").innerHTML = "Not a valid number.";
else
document.getElementById("to_value").innerHTML = factor * document.length_con.from_value.value;
}
</script>
</HeaderData>
-->
<p align="center"><h3 align="center">Choose Currency</h3></p><div align="center"> [[ConLib:custom/UserCurrencyMenuDropDown]]</div>
<p><br/>
[[ConLib:custom/HeaderBasketTotal]]
[[ConLib:custom/ShippingRates]]
</p>
<p>[[ConLib:custom/MiniBasket]] </p>
<p>[[ConLib:custom/RecentlyViewed Visible="false"]]
</p>
<h2>Length Converter</h2>
<form name="length_con">
<table>
<tr>
<td>From </td>
<td>
<select name=from_unit onChange="convert_unit()";>
<option> centimeters
<option> meters
<option> kilometers
<option> miles
<option> inches
<option> feet
<option> yards
</select>
</td></tr>
<td> To </td>
<td>
<select name=to_unit onChange="convert_unit()";>
<option> centimeters
<option> meters
<option> kilometers
<option> miles
<option> inches
<option> feet
<option> yards
</select>
</td>
</tr>
<tr>
<td> </td><td colspan="3"><div id="formula">centimeters = 1 centimeters</div></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td>Enter </td>
<td><input type="text" name="from_value" value="1" size="12" maxlength="12"></td>
</tr><td> <input type=button value="To" onClick="convert_unit()";> </td>
<td><div id="to_value">1</div></td>
</tr>
</table>
</form>
- hassonmike
- Lieutenant (LT)
- Posts: 76
- Joined: Tue Apr 19, 2011 2:13 pm
- Contact:
Re: Measurement Conversion - Java?
Thanks, Mouse, I appreciate the effort, but still no luck.