开发者

Google Maps Waypoints using Checkboxes

Can anyone tell me how to convert the following code to work using checkboxes instead..

var checkboxArray = document.getElementById("waypoints");
for (v开发者_如何学Car i = 0; i < checkboxArray.length; i++) {
  if (checkboxArray.options[i].checked == true) {
    waypts.push({
        location:checkboxArray[i].value,
        stopover:true});

I have a number of checkboxes on the page with different values in them and I would like the user to click the points they would like to add to their route.

Help!!

Cheers

Justin


This is the sample code from google documentation for google map version 3 which plots waypoints between already set start and end locations. and here is the answer.

assume that you have checkboxes like the following

<input type='checkbox' name='waypoints[]' value='someplace1'>
<input type='checkbox' name='waypoints[]' value='someplace2'>
<input type='checkbox' name='waypoints[]' value='someplace3'>
<input type='checkbox' name='waypoints[]' value='someplace4'>
<input type='checkbox' name='waypoints[]' value='someplace5'>

and then the following code will work for you.

var checkboxArray = document.getElementsByName("waypoints[]");
for (var i = 0; i < checkboxArray.length; i++) {
  if (checkboxArray[i].checked == true) {
    waypts.push({
        location:checkboxArray[i].value,
        stopover:true});

But if the user clicks the checkbox in random order then .... it is left to you to decide.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜