No announcement yet.

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

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

    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 :

    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

    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:

    HTML Code:
    <span id="sc_seleccionar_todo_bot" class="scButton_default" onmouseup="if(this.disabled){ return false; }else{'pointer'; this.className = 'scButton_onmouseover'; }" onmousedown="if(this.disabled){ return false; }else{'pointer'; this.className = 'scButton_onmousedown'; }" onmouseout="if(this.disabled){ return false; }else{''; this.className = main_style; }" onmouseover="if(this.disabled){ return false; }else{ main_style =…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.


    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


    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!!!!!
    Last edited by Robster; 05-06-2014, 06:28 PM. Reason: more findings

  • #2
    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(){

    As it was solved by Mr. Cristian Bravo... !
    Last edited by Robster; 05-06-2014, 06:32 PM.