0

I have this:

<select id="division" multiple="multiple" title="Equipos seleccionados" style="width:143px;height:125px;overflow:scroll;">
<option value="1" title="Bundesliga">Bundesliga</option>
</select>

I'm doing this:

_spBodyOnLoadFunctionNames.push("hideFields");

function hideFields() {
    var control = findcontrol("equipo");
    control.parentNode.parentNode.parentNode.style.display = "none";
}

function showFields() {
    var control = findcontrol("equipo");
    control.parentNode.parentNode.parentNode.style.display = "block";
}

function findcontrol(field) {
    var arr = document.getElementById(field);
    return arr;
}

document.getElementById("Division_AddButton").onclick = showFields();

but it does not happen to the showFields ();

What I want is that when there is nothing in division that does not show me theteam and when there is something in division that theteam appears

How do I do it in Javascript? Javascript without any bookstore. The code is generated by Sharepoint

Visual what I want:

  • At beginning

Al cargar la pagina por defecto

  • When you add an element

Al pasar una division a la parte derecha o seleccionarla

0

code looks fine. only comment i can make is that are you sure you are targeting the correct control and is it at the correct parent level. also as its from sharepoint its possible that its not been loaded in the DOM yet.

I dont know what version of sharepoint you are using? also does the hiding work in f12 developer running the js code within the browser to see if your targeting the correct control? if it is then load the control on dom load like below.

2010

function showHideCode(){
    var values = document.getElementById('division').val();;
    if (values != null || values.length > 0){
        showFields();
    }
}

_spBodyOnLoadFunctionNames.push("showHideCode");

2013

SP.SOD.executeFunc('sp.js','SP.ClientContext',showHideCode);

function showHideCode(){
    var values = document.getElementById('division').val();;
    if (values != null || values.length > 0){
        showFields();
    }
}

plain simple JS might work if the stuff you want to hide has no reliance on any of the sharepoint JS libraries to load

window.onload = function () { 

        var values = document.getElementById('division').val();;
        if (values != null || values.length > 0){
            showFields();
        }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.