Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JavaScript/jquery function needed from existing code

Posted on 2014-04-15
5
Medium Priority
?
668 Views
Last Modified: 2014-04-22
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
0
Comment
Question by:jellydeal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 40001049
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
 

Author Comment

by:jellydeal
ID: 40001223
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
 
LVL 22

Expert Comment

by:Mrunal
ID: 40001374
Hi, can you share your code, till now what you have done.

for dragging functionality, use this:

http://skidding.github.io/dragdealer/
0
 

Author Comment

by:jellydeal
ID: 40001395
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
 
LVL 6

Accepted Solution

by:
Brijesh Gandhi earned 1500 total points
ID: 40014529
 <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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question