JavaScript/jquery function needed from existing code

Hello :)
I'm  pulling my hair out with this one ;)
I am trying to create a JavaScript/jquery function that will return a calculated value based on parameters passed.

There is a site here : http://bikecalculator.com that does exactly what I need. It's written in JavaScript and the source is viewable. I need a function where I can pass the parameters that the screen asks for and it returns the POWER WATTS.

Does anyone know of an existing function that does this or can someone build one from the example site?

My gratitude will take the form of 500 points and a PayPal donation :)

Thanks in advance
jellydealAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Brijesh GandhiConnect With a Mentor ProgrammerCommented:
 <script>

		tireValues = [0.005, 0.004, 0.012];
		aeroValues = [0.388, 0.445, 0.420, 0.300, 0.233, 0.200];

function makeDecimal2 (value) {
	if (value != null && value != 0) {
		var x = Math.round(parseFloat(value) * 100);
		var d;
		if (x < 100) d=0;
		else d = parseInt(x / 100);
		var c = x % 100;
		var g = (c >= 10)?"":"0";
		value = "" + d + "." + g + c;
	}
	return value
}

function makeDecimal0 (value) {
	if (value != null && value != 0) {
		value = "" + Math.round(parseFloat(value));
	}
	return value
}

function valDecNumber(str) {  /* returns true if a valid number */
	if(str.length == 0) return false;
	var noNegSignYet = true;
	var noPointYet = true;
	for (i=0; i < str.length; i++) {
		var chr = str.substring(i, i+1)
		if (noPointYet && chr == ".") noPointYet = false;
		else if (noNegSignYet && chr == "-") noNegSignYet = false;
		else if (chr< "0" || chr > "9") {
			alert ("I don't think you want to do that, Dave.");
			return false
		}
	}
	return true
}

function empty(inputStr) {
	if (inputStr == "" || inputStr == null) return true;
	return false
}


function update(form) {

	with (document.f) {
		
		
		/* USUnits = US.checked; */
		USUnits = 0;
		/* baseMetabolism = baseMet.checked; */
		
		/* Left panel */
		vv = eval(velocity.value) / 3.6;  // converted to m/s;
		rweightv = eval(rweight.value);
		bweightv = eval(bweight.value);

		
		theTire = tire.selectedIndex;
		rollingRes = tireValues[theTire];
		theAero = aero.selectedIndex;
		frontalArea = aeroValues[theAero];
		gradev = eval(grade.value) * 0.01;
		headwindv = eval(headwind.value) / 3.6;  // converted to m/s
		distancev = eval(distance.value);
		temperaturev = eval(temperature.value);
		elevationv = eval(elevation.value);
		transv = eval(trans.value) * 0.01;
		
		if(USUnits) {      // Convert to metric units
			rweightv *= 0.4536;
			bweightv *= 0.4536;
			vv *= 1.6092;
			headwindv *= 1.6092;
			distancev *= 1.6092;
			temperaturev = (temperaturev - 32) * 0.555;
			elevationv *= 0.3048;
		}
		
		
		
		/* Left Calculation */
		density = (1.293 - 0.00426 * temperaturev) * Math.exp(-elevationv / 7000.0);
		twt = 9.8 * (rweightv + bweightv);  // total weight in newtons
		A2 = 0.5 * frontalArea * density;  // full air resistance parameter
		tres = twt * (gradev + rollingRes); // gravity and rolling resistance
		
		tv = vv + headwindv; 
		pv = (vv * tres + vv * tv * tv * A2) / transv;
		
		if (vv > 0.0) t = 16.6667* distancev / vv;  // vv is m/s here
			else t = 0.0;  // don't want any div by zero errors
		c = t / 60.0 * (pv * 4.0) / 1.163;  
			/* 1.163 is for converting watt-hours to kilocalories */
			/* energy conversion eff = 0.25 */
		wl = c / 7716;
		
		if(USUnits) {     // Convert to US units
			wl *= 2.205;
		}
		
		/* Left results */
		power.value = makeDecimal0(pv);
		time.value = makeDecimal2(t);
		calories.value = makeDecimal0(c);
		weightloss.value = makeDecimal2(wl);
		
		
	}
}
</script>

Open in new window


Above Code is calling .Related URL is Below
Site URL
I hope u get your point .Try to pass value in Update function and get result of Power WAtt
0
 
MrunalCommented:
Hi,
if you can find existing JavaScript function with developer toolbar of by saving same html page.

if you look into this, you will find that from all controls (textboxes, dropdownlist)

following function is get called:

update(calcID)
and
updateDistance(calcID,1)
0
 
jellydealAuthor Commented:
Hi,
Thanks I did do this and tried to Create a function myself using the existing code but it wouldn't work. I need a function to get called hundreds of times and the GUI slider thing on that page stalls the whole thing. I ideally just want a function .. I failed myself :(
0
 
MrunalCommented:
Hi, can you share your code, till now what you have done.

for dragging functionality, use this:

http://skidding.github.io/dragdealer/
0
 
jellydealAuthor Commented:
Hi sure ;
http://www.countrycorks.co.uk/bike/calc.htm
It processes a file, test.gpx and after pressing process, and waiting it reads in some data. Populates the form fields ,calls the update() but the watts all come out at 150. I got to the point of thining maybe it's best to reinvent the wheel on this occasion!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.