0

At the moment I'm using jQuery to check the value of the select box and the values are either true or false but when I go to select the value in the jquery it recognises it as a string.

Then I have to go change it to a Boolean for it to work in my setOptions I was wondering if it was possible to convert to Boolean without having to go through the process I've done below?

html

<select name="scalecontrol" id="scalecontrol">
    <option value="false">None</option>
    <option value="true" selected="selected">Standard</option>
</select>

jQuery

$('#scalecontrol').change(function(){
    ao.scalecontrol = $(this).val();
    if (ao.scalecontrol == 'false'){
        ao.scalecontrol = false;
    } else {
        ao.scalecontrol = true;
    }
    map.setOptions({
        scaleControl:ao.scalecontrol
    });
});
3
  • see stackoverflow.com/questions/263965/… Commented Nov 11, 2013 at 11:53
  • I deleted my answer because a) it was overkill (thanks @musefan) and b) it's already been answered before Commented Nov 11, 2013 at 11:57
  • try this ao.scalecontrol = ($(this).val() === 'true'); Commented Nov 11, 2013 at 11:59

2 Answers 2

2

If using .val() results in a string type then you have to work with that, however you can shorten your code to the following:

$('#scalecontrol').change(function(){
    ao.scalecontrol = $(this).val() == 'true';
    map.setOptions({
        scaleControl:ao.scalecontrol
    });
});
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

$('#scalecontrol').change(function(){
    map.setOptions({
        scaleControl: $(this).val() === "true"
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.