TheBnl Posted May 28, 2012 Share Posted May 28, 2012 (edited) I'm working on a site and i want to use icons to select travel modes,i have an working function but it only works with a selection input.Is there a way to modify it to be used with buttons? Thanks in advance! Function: function calcRoute() { var selectedMode = document.getElementById("mode").value; var request = { origin: thuis, destination: kabk, // Note that Javascript allows us to access the constant // using square brackets and a string value as its // "property." travelMode: google.maps.TravelMode[selectedMode] }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); HTML - Select input <select id="mode" onchange="calcRoute();"> <option value="DRIVING">Driving</option> <option value="WALKING">Walking</option></select> HTML - Button input (?) <form id="mode"> <input type="button" onchange="calcRoute();" value="DRIVING"> <input type="button" onchange="calcRoute();" value="WALKING"></form> Edited May 28, 2012 by TheB Link to comment Share on other sites More sharing options...
Ingolme Posted May 28, 2012 Share Posted May 28, 2012 Pass a parameter to the function instead of accessing the element from the function. Buttons use the onclick event, not the onchange event. <input type="button" onclick="calcRoute('DRIVING');"><input type="button" onclick="calcRoute('WALKING');"> Don't forget to erase the line that's currently setting the selectedMode variable. function calcRoute(selectedMode) {... 1 Link to comment Share on other sites More sharing options...
TheBnl Posted May 28, 2012 Author Share Posted May 28, 2012 It works great! it is so logical to, onClick and onChange Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now