1

Answer:

I figured it out (or at least worked around it). I used document.getElementById(researcher).show; instead of $$(researcher).each(function(element) element.show();

and it works perfectly now.

I am trying to use javascript to only display data from a specific owner. Is there any way I can use the results from a SOQL query as a div id?

Here is a snippet of what I want to do:

<select name="r" id="r" onchange="selectResearcher()">
    <option></option>
    <option value="name">Name/option>
    <option value="name1">Name1</option>

div class="output" id="{!less.Lead_Analyst__r.LastName}"

here is the javascript portion of my code:

<script>

    function selectResearcher(){ 
        researcher = $F('r'); 
        if(researcher.length > 1) { 
            $$('div.output').each(function(element){
                element.hide();
            });
            $$(researcher).each(function(element){
                element.show();
            });
        }
        else{
            $$('div.output').each(function(element){
                element.show();
            });
        }
    }


</script>

Thanks

2
  • I need all the data no matter what user or owner. I have a select list that uses javascript to tell which data should be displayed by getting the div id depending on what selection is made – user3858610 Aug 5 '14 at 18:00
  • Where are you executing that SOQL ? How's your page setup ? Without context and details it's hard to answer your question, could you update it with more info ? Possibilities are using apex tags to create divs, or composte html in JS through javascript remoting, or other options depending on what you're already doing .. – Samuel De Rycke Aug 5 '14 at 18:09
1

There are a ton of ways to do this, eith via JSRemoting or through an apex:repeat. Either way you can return everything and then use $j(".class"/"#id").hide() if the data tag isnt the right name. Sorta like this, sorry if this isn't super well explained, hopefully it helps.

Try using it in a data tag as such

<apex:repeat value="{!someGetterMethod}" var="LeadName">
    <div class="output" data-aName="{!LeadName.LastName}"> </div>
</apex:repeat>

then from your jquery code, if that is what you are using; you can reference it as such :

(if this is in an Apex:Repeat tag)

$j(".output").each(function(index, value) {

if($j(this).data('aName') == "LastNameOfSomePerson")
{
$j(this).show(); //or hide();
}

});
2
  • this is almost exactly what I need but I'm using javascript. Thanks for the help – user3858610 Aug 5 '14 at 18:24
  • Can you post more of your code, I'll gladly help more if I can! :) – KidNiki Aug 5 '14 at 18:25

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.