Javascript Button - How to select all options in a multiple select input

Hello everyone!

My name is Roberto and I came around cause my boss did buy online support for scriptCase v7 and we got a license for v6 :stuck_out_tongue:

If this is not the best place to post these sort of questions, please admins donā€™ blame on a noob and move it accordingly.

Anyways, here we go:

I made a ā€œselect allā€ kind of javascript button inside a form just to select all the options inside a multiple select input referred as ā€œv_patenteā€ in SC

Basically, the code goes just like this:


var selectBox = document.getElementById('id_sc_field_v_patente');
var aux_count;
for (aux_count = 0; aux_count < selectBox.options.length; aux_count++) 
{ 
	document.getElementById('id_sc_field_v_patente').options[aux_count].selected = true; 
} 

return true;

I know that code is jerky somehowā€¦ but I just wanted to be sure that javascript is not throwing errors at allā€¦

my aux_count variable is working

but if i try something just like this :

alert(document.getElementById('id_sc_field_v_patente').options[aux_count].innerHTML);

I got nothingā€¦

If I try to pull that off directly from the console it just worksā€¦ however SC doesnā€™t want it to happenā€¦ and thatā€™s why Iā€™m here :frowning:

I could also notice that in HTML after my new javascript button is called by onclick event, SC adds a ā€œreturn false;ā€ statementā€¦

it looks like this:


<span id="sc_seleccionar_todo_bot" class="scButton_default" onmouseup="if(this.disabled){ return false; }else{ this.style.cursor='pointer'; this.className = 'scButton_onmouseover'; }" onmousedown="if(this.disabled){ return false; }else{ this.style.cursor='pointer'; this.className = 'scButton_onmousedown'; }" onmouseout="if(this.disabled){ return false; }else{ this.style.cursor=''; this.className = main_style; }" onmouseover="if(this.disabled){ return false; }else{ main_style = this.cl?cursor='pointer'; this.className = 'scButton_onmouseover'; }" style="vertical-align: middle; display:inline-block;" title="Haga clic en este bot?n para seleccionar todas las patentes" onclick="[B]sc_btn_seleccionar_todo(); return false;[/B]">

Any help would be really appreciated.

Saludos!

EDIT: Additional info:

Select element is previously fullfiled by an SQL query

Then I thought that sc_getfield() method could be helpful because Iā€™m working on a control.

But now I got a message error saying itā€™s not defined. This already happens even if I use other methods such as

sc_alert(ā€œholaā€)

I got the same errorā€¦ Do I have to load something else previously ? attach this thing to some other event such as on app init or something like that?

ayudaaaaaaaaaa csm!!!

Ok, got a proper answer for this oneā€¦

What was wrong in my case: JS was using square brackets [] for itā€™s syntax and SC already use those for itā€™s own purposesā€¦

So, the workaround came in the form of jQuery just like this:

$.each($("#id_sc_field_v_patente>option"), function(){
$(this).attr(ā€œselectedā€,ā€œselectedā€);
});

As it was solved by Mr. Cristian Bravoā€¦ ! :smiley: