SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Conspiracy's Avatar
    Join Date
    May 2002
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Highlight and CheckAll Script not Wroking together

    I'm using these two scripts together, one that when you check a row, it changes the colour and one to check all boxes. But now the highlight one isn't working anymore.

    Here's the highlight script:

    <!--//
    // Tipos de Ação
    //===================================
    var ST_INSERT = 1;
    var ST_EDIT = 2;
    var ST_DELETE = 3;
    var ST_REFRESH= 4;
    //===================================
    var SelectedItem = new Array();
    var SmtGridFrm = document.forms[0];
    function GridSel(id, check) {
    SmtGridFrm = document.forms[0];
    var checks = SmtGridFrm.elements;
    for (i=0; i<checks.length; i++) {
    if (checks[i].type == "checkbox" && checks[i].checked) {
    line = 'GridItem' + checks[i].value;
    c = SmtGridFrm.all[line];
    //c.style.backgroundColor = '#DFDFFF';
    c.className = 'GridItemSel';
    }
    }
    line = SmtGridFrm.all['GridItem' + id];
    if (check.checked) {
    line.className = 'GridItemSel';
    SelectedItem[id] = true;
    } else {
    line.className = 'GridLine';
    SelectedItem[id] = false;
    }
    }

    function hasChecked() {
    SmtGridFrm = document.forms[0];
    var checked = false;
    var checks = SmtGridFrm.elements;
    for (i=0; i<checks.length; i++) {
    if (checks[i].type == "checkbox") {
    checked = checks[i].checked;
    if (checked) break;
    }
    }
    return checked;
    }

    function doMenuAction(actionType, url, wndName, wParam) {
    SmtGridFrm = document.forms[0];
    switch (actionType) {
    case ST_INSERT:
    if ( wndName ) {
    wnd = window.open(url, wndName, wParam);
    wnd.focus();
    } else {
    window.document.location.href = url;
    }
    break;
    case ST_EDIT:
    if ( hasChecked() ) {
    var selected = getSelectedItems();
    if ( selected ) {
    SmtGridFrm.SO_STATE.value = ST_EDIT;
    url += (url.indexOf('?') == -1 ? '?' : '&') + selected;
    submitTo(SmtGridFrm, url, wndName);
    } else {
    alert('Por favor, selecione o item desejado antes de editá-lo.');
    }
    } else {
    alert('Por favor, selecione o item desejado antes de editá-lo.');
    }
    break;
    case ST_DELETE:
    if ( hasChecked() ) {
    if (confirm("Deseja realmente excluir este(s) item(ns)?")) {
    var checks = SmtGridFrm.elements["gridSelected[]"];
    if ( checks ) {
    if ( checks.length) {
    for ( var i=0; i<checks.length; i++) {
    checks[i].name = 'SO_KEY[]';
    }
    } else {
    checks.name = 'SO_KEY[]';
    }
    }
    SmtGridFrm.SO_STATE.value = ST_DELETE;
    SmtGridFrm.action = url;
    SmtGridFrm.submit();
    }
    } else {
    alert('Por favor, selecione os itens desejados antes de excluí-los.');
    }
    break;
    case ST_REFRESH:
    window.document.location.reload();
    break;
    }
    }

    /************************************************************************************************
    * Autor: Alexandre Dias *
    * Descrição: abre uma popup *
    ************************************************************************************************/
    function openWindow(theURL, winName, hasScrollBar) {
    var scBar = ''
    if(!winName) winName = 'janela'
    if(hasScrollBar) var scBar = ',scrollbars=yes';
    newWin = window.open(theURL,winName,'width=1,height=1'+ scBar);
    newWin.focus();
    return newWin;
    }

    /************************************************************************************************
    * Autor: Alexandre Dias *
    * Descrição: submete um form para a url e target definidos *
    ************************************************************************************************/
    function submitTo(frm, url, wName, resetCurrent) {
    var _tgt = frm.target;
    var _act = frm.action;
    if ( wName ) {
    var w = openWindow(url, wName);
    frm.target = wName;
    }
    frm.action = url;
    frm.submit();
    if (resetCurrent) {
    document.location.href = 'about:blank';
    }
    frm.target = _tgt;
    frm.action = _act;
    }

    /************************************************************************************************
    * Autor: Alexandre Dias *
    * Descrição: retorna array com items selecionados no grid *
    ************************************************************************************************/
    function getSelected() { //as Array
    var values = new Array();
    for (var key in SelectedItem) {
    if ( SelectedItem[key] ) {
    values[values.length] = key;
    }
    }
    return values;
    }

    /************************************************************************************************
    * Autor: Alexandre Dias *
    * Descrição: retorna os items selecionados como SO_KEY *
    ************************************************************************************************/
    function getSelectedItems() { //as String
    return getSelectedAs('SO_KEY');
    }

    /************************************************************************************************
    * Autor: Alexandre Dias *
    * Descrição: retorna os items selecionados como SO_PARAM *
    ************************************************************************************************/
    function getSelectedAsParams() { //as String
    return getSelectedAs('SO_PARAM');
    }

    /************************************************************************************************
    * Autor: Alexandre Dias *
    * Descrição: retorna os items selecionados com qquer nome de variavel *
    ************************************************************************************************/
    function getSelectedAs(sAlias) { //as String
    var vName = sAlias.toString() +'[]';
    return vName +'='+ getSelected().join('&'+ vName +'=');
    }
    /*
    Limpa Formulário

    */
    function clearForm(){
    el = form1.elements
    for(i = 0;i < el.length; i++){
    if(el[i].type == "text") el[i].value = "";
    }
    }
    //-->

    Adding this to the checkbox:
    <input type="checkbox" name="list" value="3" name="gridSelected[]" onChange="GridSel('3', this)" onClick="GridSel('3', this)" class="checkbox">


    And the checkAll:

    <script type="text/javascript">
    var checkflag = "false";
    function check(field) {
    if (checkflag == "false") {
    for (i = 0; i < field.length; i++) {
    field[i].checked = true;}
    checkflag = "true";
    return "Uncheck All"; }
    else {
    for (i = 0; i < field.length; i++) {
    field[i].checked = false; }
    checkflag = "false";
    return "Check All"; }
    }
    </script>

    Adding this to the checkbox:

    onClick="this.value=check(this.form.list)"


    How can I make both of them work????

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you start with this:

    <input ... onClick="GridSel('3', this)" ...>

    and do this:
    Adding this to the checkbox:
    onClick="this.value=check(this.form.list)"
    Then, your checkbox will only do this:

    <input ... onClick="this.value=check(this.form.list)" ...>

    In other words, you can't have two separate 'onclick' attributes in the tag: the last one will overwrite the first one.

    So, if you want both functions to execute when you click on the checkbox, do this:

    <input ... onClick="GridSel('3', this);this.value=check(this.form.list)" ...>

  3. #3
    SitePoint Zealot Conspiracy's Avatar
    Join Date
    May 2002
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem with them is that I have a table, with the head row with the titels, and on the checkbox column from the head is the check all script, not on the others checkboxes, these ones have only one OnClick event, but the highlight gets all funny when I check all of them and uncheck some, the script is not running the way it should...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •