homepage Welcome to WebmasterWorld Guest from 54.196.225.45
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Need help
calulating price and size
locking




msg:3727160
 1:52 pm on Aug 20, 2008 (gmt 0)

Have a big trouble with calculating size, by mistake i have ereased everything in modules/Calculator/steps.php. what should be there to extract values and make this work?

i still got

tip.js
-----------------------------------------------------
var showing = false;

if (document.layers) document.captureEvents(Event.MOUSEMOVE);

function showTip(){

var browser=navigator.appName;
if(!showing){
var obj = document.getElementById("terms");
var left = 0;
var top = 0;
if(obj.offsetParent){
//while(obj.offsetParent){
left += obj.offsetLeft;
top += obj.offsetTop;
//obj = obj.offsetParent;
//}
}
var div = document.getElementById("terms_info");
if(div != null){
div.style.position = "absolute";
div.style.display = 'block';
div.style.width = '500px';
div.style.height = '70px';
div.style.zIndex = 10;

if(browser == "Microsoft Internet Explorer"){
div.style.left = left -180 + "px";
div.style.top = top + 350 + "px";
}else{
div.style.left = left + "px";
div.style.top = top + "px";
}

showing = true;
}
}else{
hideTip();
}
}

function hideTip(){
if(document.getElementById("terms_info") != null){
var div = document.getElementById("terms_info");
if(div != null){
div.style.display = 'none';
div.style.width = '0px';
div.style.height = '0px';
showing = false;
}
}
}

This is calc.js
-----------------------------------------------------

var pr;
var qt = 1;
var tp;
var cam = 3;
var wd;
var hg;
var upr;

var xmlHttp;

function step2(type, num){

tp = type;

if (xmlHttp==null){
xmlHttp=GetXmlHttpObject();
if(xmlHttp == null){
alert ("Browser does not support HTTP Request1");
return
}
}

if(document.getElementById("type2") != null){
markPicture(type, num);

var qty = document.getElementById("q").value;
var cameras = cam;
var width = document.getElementById("w").value;
var height = document.getElementById("h").value;

var params = "?step=4&type=" + type + "&width=" + width + "&height=" + height + "&cameras=" + cameras;
if(IsNumeric(width) && IsNumeric(height) && IsNumeric(qty)){
var url="modules/Calculator/steps.php" + params;
xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=function func1(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
var result = new Array();
result = xmlHttp.responseText.split(";");

var unitPrice = parseFloat(result[0]);
upr = unitPrice;
var price = qty * unitPrice;
price = Math.round(price * 100)/100;


document.getElementById("price").innerHTML = price;
pr = price;
tp = type;

document.getElementById("type2").innerHTML = result[1];
scroll(type);
if(document.getElementById("w") != null){
document.getElementById("w").focus();
}
}
}
xmlHttp.send(null);
}
}
else{
var params = "?step=2&type=" + type;
var url="modules/Calculator/steps.php" + params;
xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=function func(){

if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
markPicture(type, num);
scroll(type);
document.getElementById("step2").innerHTML=xmlHttp.responseText;
if(document.getElementById("w") != null){
document.getElementById("w").focus();
}
}
}
xmlHttp.send(null);
}
}

function step3(){

if (xmlHttp == null){
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null){
alert ("Browser does not support HTTP Request2");
return;
}
}

var type = tp;

var next = false;
var width = document.getElementById("w").value;
var height = document.getElementById("h").value;

wd = width;
hg = height;

if(width.length > 0 && height.length > 0){
if(IsNumeric(width) && IsNumeric(height)){

var params = "?step=3&width=" + width + "&height=" + height + "&type=" + type;
var url="modules/Calculator/steps.php" + params;
xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=function func(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
if(xmlHttp.responseText == null ¦¦ xmlHttp.responseText == ''){
document.getElementById("step3").innerHTML= "Storleken ni söker finns ej. Prova en liknande storlek.";
}else{
document.getElementById("step3").innerHTML=xmlHttp.responseText;
upr = document.getElementById("hupr").value;
}
}

}
xmlHttp.send(null);
}
else{
document.getElementById("step3").innerHTML = "Bredd och höjd sklall skrivas med nummer!";
}
}

}

function step4(qty){//when changing qty in texfield

if(upr == "undefined" ¦¦ upr == null){
upr = parseFloat(tmpUpr);
}
qt = qty;
var price = qty * upr;
price = Math.round(price * 100)/100;
pr = price;
document.getElementById("price").innerHTML = price;
}

function submitOrder(){

var width = wd;
var height = hg;

var cameras = cam;
var type = tp;
var price = pr;
var qty = qt;

if (xmlHttp==null){
xmlHttp=GetXmlHttpObject();
if(xmlHttp == null){
alert ("Browser does not support HTTP Request3");
return
}
}
var params = "?step=5&width=" + width + "&height=" + height + "&cameras=" + cameras + "&type=" + type + "&price=" + price + "&qty=" + qty;
var url="modules/Calculator/steps.php" + params;
xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=function func(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
document.getElementById("step1").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.send(null);

document.getElementById("step1").innerHTML = "";
document.getElementById("step2").innerHTML = "";
document.getElementById("step3").innerHTML = "";
}

function step6(customer){

if (xmlHttp==null){
xmlHttp=GetXmlHttpObject();
if(xmlHttp == null){
alert ("Browser does not support HTTP Request4");
return
}
}

if(document.getElementById("step2") != null){
document.getElementById("step2").innerHTML = "";
}

var params = "?step=6" + "&customer=" + customer;
var url="modules/Calculator/steps.php" + params;
xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=function func3(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
document.getElementById("custom_fields").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.send(null);
}

function order(customer){

if(customer == "p"){

var address = document.getElementById("address").value;
var customParams = "&address=" + address;

}else{

var company = document.getElementById("company").value;
var address = document.getElementById("address").value;
var code = document.getElementById("code").value;
var pvm_code = document.getElementById("pvm_code").value;
var customParams = "&company=" + company + "&address=" + address + "&code=" + code + "&pvm_code=" + pvm_code;

}

var name = document.getElementById("name").value;
var phone = document.getElementById("phone").value;
var email = document.getElementById("email").value;

var width = wd;
var height = hg;
var cameras = cam;
var type = tp;
var price = pr;
var qty = qt;

if (xmlHttp==null){
xmlHttp=GetXmlHttpObject();
if(xmlHttp == null){
alert ("Browser does not support HTTP Request5");
return
}
}

var params = "?step=order" + "&customer=" + customer + "&width=" + width + "&height=" + height + "&cameras=" + cameras + "&type=" + type + "&price=" + price + "&qty=" + qty + "&name=" + name + "&email=" + email + "&phone=" + phone + customParams;
var url="modules/Calculator/steps.php" + params;
xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=function func(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
var result = xmlHttp.responseText;
if(result != 'no_errors'){
var errors = new Array();
errors = result.split(";", result.length);
var out1 = "<fieldset>";
out1 = "Vänligen ändra följande fält:<br>";
var out2 = "<br>";
for(var i = 0; i < errors.length; i++){
if(errors[i] != ''){
out2 = out2 + errors[i] + "*<br>";
}
}
var out = out1 + out2;
out = out + "</fieldset>";
document.getElementById("step2").innerHTML = out;
}else{
document.getElementById("step1").innerHTML = "Din förfrågan, är mottagen, vi återkommer så snart vi kan Continue browsing.";
document.getElementById("step3").innerHTML = '<input type="button" value="Fortsätt" onClick="(location.reload(true))">';
if(document.getElementById("step2") != null){
document.getElementById("step2").innerHTML = "";
}
}
}
}
xmlHttp.send(null);

}

function cameras(camerasNum){

cam = camerasNum;
var width = document.getElementById("w").value;
var height = document.getElementById("h").value;
var qty= document.getElementById("q").value;

var type = tp;

if (xmlHttp==null){
xmlHttp=GetXmlHttpObject();
if(xmlHttp == null){
alert ("Browser does not support HTTP Request6");
return
}
}

var params = "?step=4&type=" + type + "&width=" + width + "&height=" + height + "&cameras=" + camerasNum;
var url="modules/Calculator/steps.php" + params;
xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=function func(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
var result = new Array();
result = xmlHttp.responseText.split(";");

var unitPrice = parseFloat(result[0]);
upr = unitPrice;
var price = qty * unitPrice;
price = Math.round(price * 100)/100;
document.getElementById("price").innerHTML = price;
pr = price;
document.getElementById("type2").innerHTML = result[1];
}
}
xmlHttp.send(null);
}

function Clear(){

document.getElementById("step3").innerHTML = "";
document.getElementById("w").value = "";
document.getElementById("h").value = "";

}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari, IE7
xmlHttp=new XMLHttpRequest();
}
catch(e){
//Internet Explorer
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch(e){
alert("Unable to create HTTP Request7");
}
}
return xmlHttp;
}

function IsNumeric(number) {

var nums = "0123456789";
if (number.length==0){
return false;
}
for(var n=0; n < number.length; n++){
if(nums.indexOf(number.charAt(n))==-1){
return false;
}
}
return true;
}

function scroll(type) {
var obj;
var obj2;
obj = document.getElementById("step2"); //object to scroll to
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;

//var cof = curtop / 50;
var currentPos;
if(type != 'undefined'){
obj2 = document.getElementById("type_pic" + type); //object to scroll from
if (obj2.offsetParent) {
currentPos = obj2.offsetTop;
}
}else{
currentPos = 0;
}
for(var i = currentPos; i < 1000; i = i + 3){
window.scrollTo(curleft, i);
}
}
}

function markPicture(type, num){

document.getElementById("type_pic" + type).style.backgroundColor="#FECA0D";
document.getElementById("type_pic" + type).style.borderColor="#FECA0D";

for(var i = 1; i < num + 1; i++){
var name = "type_pic" + i;
if(i != type && document.getElementById(name) != null)
document.getElementById(name).style.backgroundColor='';
document.getElementById(name).style.borderColor='';
}
}

 

Dabrowski




msg:3727402
 5:13 pm on Aug 20, 2008 (gmt 0)

Thinking: I suspect you've found a site that sells something, maybe cameras? You liked the popup picture, so you copied the script and now don't know how to make it work.

No problem, some of the best scripts are inspired by other sites, and I think everyone pinches code to aid their own.

Anyway, regardless of that, why don't you tell us what you're trying to do and we can help you write some code?

Glancing at the script you've posted I'm guessing it's a scrolling image gallery with some popup pictures?

locking




msg:3727628
 9:21 pm on Aug 20, 2008 (gmt 0)

Hi :)
I have worked with a guy and he have got that script somewhere and made some changes, the script should count out price and size of windows and doors (pvc), now we have gone separate ways and he won´t share the script.
It doesn´t open any windows but it scrolls down to a menu after you
click on a image there you can enter height and width and press
calculate to find out price which you later on can send to mail with extra details about adress and name.
I would pay for such script but it´a jungle out there and i don´t really know what to look for. Suggestions would be appricieted.

this is index page

<script src="count/calc.js"></script>
<script src="count/tip.js"></script>
<div id="step1">
<h3>Välj fönstertyp</h3>
<div id="gallery">
<div id="type_pic1"><img src="/uploads/images/calculator/TYPE1.jpg" onClick="step2(1, 11)"></div>
<div id="type_pic2"><img src="uploads/images/calculator/TYPE2.jpg" onClick="step2(2, 11)"></div>
<div id="type_pic3"><img src="uploads/images/calculator/TYPE3.jpg" onClick="step2(3, 11)"></div>
<div id="type_pic4"><img src="uploads/images/calculator/TYPE4.jpg" onClick="step2(4, 11)"></div>
<div id="type_pic5"><img src="uploads/images/calculator/TYPE5.jpg" onClick="step2(5, 11)"></div>
<div id="type_pic6"><img src="uploads/images/calculator/TYPE6.jpg" onClick="step2(6, 11)"></div>
<div id="type_pic7"><img src="/uploads/images/calculator/TYPE7.jpg" onClick="step2(7, 11)"></div>
<div id="type_pic8"><img src="/uploads/images/calculator/TYPE8.jpg" onClick="step2(8, 11)"></div>
<div id="type_pic9"><img src="/uploads/images/calculator/TYPE9.jpg" onClick="step2(9, 11)"></div>
<div id="type_pic10"><img src="uploads/images/calculator/TYPE10.jpg" onClick="step2(10, 11)"></div>
<div id="type_pic11"><img src="uploads/images/calculator/TYPE11.jpg" onClick="step2(11, 11)"></div>
</div></div><div id="step2"></div><br /><div id="step3"></div>
</div>

Arno_Adams




msg:3728031
 1:56 pm on Aug 21, 2008 (gmt 0)

Hi,

Without the formula for calculating the price based on quantity and/or dimensions and/or weight it's impossible to recreate.

Tom

Dabrowski




msg:3728324
 7:10 pm on Aug 21, 2008 (gmt 0)

I would pay for such script

Don't be silly, this site is full of people who write this stuff in our sleep! Of course we'll help. It's going to be quite big though so it'll take a while to perfect it.

Arno is right though, you'll need to tell us your formula to add it into the script.

How are the pictures in your gallery arranged? Do you need help with the HTML/CSS too?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved