How to change the active of each controls in OpenLayers.Control.NavToolbar - javascript

I have OpenLayers.Control.NavToolbar that is working fine.
But I need to unselect a PANTOOL and select the ZOOMTOOL instead.
Is there any function to do that?

Should be something like
enter code here
// var bar = your_ol_control_navtoolbar
bar.controls[0].deactivate();
bar.controls[1].activate();
hope, it helped

Use activateControl method to choose control to active.
var navToolbar = new OpenLayers.Control.NavToolbar()
navToolbar.activateControl(navToolbar.controls[0]); //will choose PANTOOL
// If you want to choose another control.
// Just change the index at navToolbar.controls[0]

Related

How to set select2 to a specific value?

I have a website. There you can either go manually to a specific site, or go there by using a dropdown menu (select2).
If I go there manually (link), I want to change the value in the dropdown to the sites one.
Here is my select2 code:
$(function () {
$("#siteSelect").select2().on("select2:select", function (e) {
$("#siteSelect").val(-1).trigger("change");
var id = $(this).val();
var url = siteRoot + "/site/site?siteID=" + id ;
$("#Container").load(url);
});
});
Can you give me some hints how to do that?
I tried to set the value by:
$("#siteSelect").val(siteName);
Every help is appreciated!
$("#siteSelect").select2().select2('val','your value');
The select2 objects are not able to detect changes and the require you to do that manually as of now. The way to do that is as follows.
$("#siteSelect").val('<your value>');
$("#siteSelect").trigger('change');
The .trigger() call on an object lets select2 know of any changes it needs to be aware of. Unfortunately this is the only solution for v4.0.0 unless a newer version fixes this issue.

Get selected option

I want to fetch the selected option from dropdown. I know I can get selected option with jQuery(dropdown).val(). But I am not able fetch the selected with the 'val' function.
Am I doing anything wrong here?
Just use this:
var selectedValue = $('.daterange-preset').val();
(Note: I was able to see your code and get your class name by zooming in, but in the future please post the code rather than a screenshot.)
try using .on( "change" and then finding the option where selected has been applied. I have attached a jsfiddle with a working example that will alert you the value of the selected option everytime you change it.
$('.datarange-preset').on( "change", function(){
var datarangeSelected = $('.datarange-preset').find(":selected").val();
alert(datarangeSelected);
});
http://jsfiddle.net/g8hVA/
I figured out the issue. In my code at one place dropdown value was getting set with the null.
$daterangePreset.val(someVarialwithNullValue);
Because the value was getting set with null. I don't see any update in the HTML. HTML still shows one of the option as 'selected'. So when I was trying to get the selected value with following syntax it was always returning null.
$daterangePreset.val();
You can use a variant of:
var text = $("option:selected").text();
var value = $("option:selected").val();

set CheckColumn as checked programmatically

I am using 'CheckColumn' in 'gridpanel' and also I am using a window which contain a chart. In the window, when I click on some values in the chart, I have to set the corresponding check box as checked in the grid. My question is how to set a check box as checked programmatically? I got the row id of the corresponding value that I need but I do not know how to use it to check it.
Thanks a lot!
// in the code below, i am searching for the specific row how contain my value
grids.getStore().each(function(rec){
var rowData = rec.data;
if (rowData['value']==value)
{
var record = grids.getStore().getAt(rec.index);
// what i can do now? // thanks
}
});
i found what i need , just: add
rec.set('myfield', true);
thanks

How to change/set value in kendo combobox

Can anyone let me know how can we change the value of kendo combobox dynamically.
Fiddle is here - http://jsfiddle.net/ashwyn/yL6w3/1/
In the above fiddle, when we click on click then the shown value should be changed to three (for eg.)
I found this link which list all datasource methods -
http://www.kendoui.com/documentation/framework/datasource/methods.aspx
If you know the value you want, you can also do:
$("#MyComboBox").data("kendoComboBox").value(id);
working demo http://jsfiddle.net/Bxsge/2/ or http://jsfiddle.net/Bxsge/1/ (behavior for demo when you will click on the link the select will change to three selected value.)
selects by jQuery object // selects by index combobox.select(1); // selects item
link: http://www.kendoui.com/documentation/ui-widgets/combobox/methods.aspx
Hope this helps, :)
code
$(function(){
var CB = $("select").kendoComboBox();
$("a").click(function(){
var $cbx = $("select").data("kendoComboBox")
$cbx.select(2);
});
});
​

How to add more options in Javascript dependent options?

I want to add more dropdown options in this file:
http://parseven.com/java_ex.html
Now it has two and I want to make three more. Third option must be dependent on second option and so on.
Please advise me. Thanks in advance.
Where is the data coming from? I'm not sure which part of the answer you need most:
You need to add an event handler to the OnChange event of the first dropdown.
In the event handler, you need to get the data from somewhere (AJAX?)
Then you need to take the new data and add it to the second dropdown.
Here is basically what you do:
document.getElementById('dropdown1').onchange = yourFunction;
function yourFunction() {
//Here is where you need to get the data
//Then you need to add them to the other dropdown like this:
var dropdown2 = document.getElementById('dropdown2');
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
dropdown2.options.add(optn);
}

Categories