Default selection on a Radio Button selector

Hello there,

Recently I was having issues with a selector that was selecting a radio button but it wasn’t selecting the first element by default and I couldn’t use a slice selector to solve that issue. So, I had to implement this code to do it using javascript.

It is very simple, you just need to insert an HTML Container and add this code to it:


<script type="javascript">

radioButtonIndex = 0; // change here the index if you have more than 1 radiobutton selector

document.body.addEventListener('mouseover',modifySelection,true);

function modifySelection(){ 

 radioButtonObj = document.querySelectorAll('[name='+ document.getElementsByClassName('mstrmojo-ListBase mstrmojo-RadioList')[radioButtonIndex].getAttribute('id') +']');

 selected = false;

  for(i = 0; i < radioButtonObj.length ; i++) {

	selected = radioButtonObj[i].checked;

	if(selected == true) {break;}

  }

	if(selected == false){
		radioButtonObj = mstrmojo.all[document.getElementsByClassName('mstrmojo-ListBase mstrmojo-RadioList')[radioButtonIndex].getAttribute('id')];
		radioButtonObj.selectedIndex = 0;
		radioButtonObj.value = 1;
		radioButtonObj.idx = 0;
		radioButtonObj.checked = true;
		radioButtonObj.onchange();
	}
}

</script>

You just need change the radioButtonIndex in case you have more than 1 radio button in your dashboard. Just test 0, 1, 2… until you find the right one.

Hope it helps.

God bless you!

2 Replies to “Default selection on a Radio Button selector”

    1. Hi Eyal,

      I didn’t try with dashboards, but I believe so. But you probably need to modify the ids and check if the radio button class is the same in a VI dashboard.

      Best regards,

      Felipe Vilela

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s