Getting pcs:foreach to iterate a Javascript array

Dear Experts,
I've got a selection list in a content item, and I can happily use <pcs:foreach> to iterate over it.
So now, I would like to add an additional item to that which the user has selected, or get rid of some of the items.
I have been able to get the values that I want intop a javascript array, but <pcs:foreach> to iterate. I have tried a delimited string with both a spaces and commas, no luck.
Any ideas on programatically editing a selection list, or getting <pcs:foreach> to deal with an array?
Thanks!
Rob
PS Here's the code !
<script>
var NewsCategoriesToShow = myArray.split(',');
</script>
This fails: <pcs:foreach var="cat" expr="NewsCategoriesToShow">
This also fails: <pcs:foreach var="cat" expr="myArray">
Only this works: <pcs:foreach var="cat" expr="mySelectionList">
...

have you tried using straight javascript or jquery to edit the selection list after it is built? like with some javascript at the bottom of the page? i'll see if i can dig up any old code to see if i find that i've done this before.

Similar Messages

  • How to pass java arraylist into javascript arrays

    Hi, i have declare an arraylist
    ArrayList list1 = new ArrayList();Inside the arraylist, there are elements. Now, i wan to pass the elements in the java arraylist into javascript arrays but i encounter javascript errors.
    This is how i code.
    var arr1 = new Array();
    <%
    for ( int x =0; x<list1.size(); x++)
    %>
         arr1[<%=x%>] = <%=(String)list1.get(x)%>;
    <%
    %>how do i solve this problem?
    Thanks for the guidance in advance

    JTech wrote:
    Hi,
    Use Quotes around string value ( arr1[indexposition] = "stringvalue";), when assign to javascript array as below.
    arr1[<%=x%>] = "<%=(String)list1.get(x)%>"; Regards,
    Ram.Hi Ram,
    How about using arr1 = <%=list.toArray()%> ??? Is this possible? I tried it but was not working on my IDE. Do you have any solutions for this??
    Regards,
    Thiagu

  • Load CF varibales into javascript array without outputing to source code

    I have a javascript array for dynamic dropdowns - Automobile, makes,models, etc.
    The javascript arrays are populated by by cf queries
    Everythign works and functions fine - but it also loads the entire array (hundreds of lines of code) into the browser source code.
    I would like to have the javascript arrays hidden from the browser source code by calling it:
    <script language="JavaScript" type='text/javascript' src='../js/super.js'></script>
    But when I code like this, the js file 'super.js' does not run the cf variables.
    The only way I can get it to function right now is to save a cf file called 'super.cfm' and have it run the cf query, then list the javascript code under the query on this cf template.
    THis works - but again, it causes the entire javascript code to be visible to the browser source code...
    any ideas? - I am on cf 7
    thanks in advance

    thanks for your idea
    I ended up rethinking the whole process and realized that I only update my vehicle make/model list about once a week
    So what I ended up doing was creating the the dynamic javascript arrays through cf - and rendered them in a browser, then took the browser source code (the fully rendered javascript arrays) and saved them as a static js file
    My website uses this js file on every page, so I no longer need to call queries on every single page to populate the javascript arrays - they are already built and I am guessing cached by the browser  (browsers cache js files right?)
    SO this runs more efficiently.
    The only draw back is that when I add a new vehicle to the list in my database, I will need to manually do the same process of rendering the new js code, then cutting and pasting it into my static js file that gets called by all pages.
    So it loses the realtime updates - but this only happened once a week anyway - and it only takes me five minutes to create the new file.
    We'll see if I get sick of manually creating a new js file each week - probably, but this seems better than making the server re-render the code on each page.
    Does this make sense? - would this be less overhead on the server than implimenting your concept?
    thanks.

  • Java Vector to Javascript Array

    Hi all, im facing a potential problem and would be very grateful for any help on the following
    I want a Vector (rather several Vectors) comprising of serializable plain old java objects. I will have a JSP or plain HTML (probably JSP) page containing, amongst other things, a javascript array or set of arrays i want to have populated with the contents of the vectors . . .
    Is this possible? not after code really just a feasible way of implementing this . . .it mi9ght turn out that it cann all be done via JSP / Java.
    P.S. Asan after thought, when writing this,anyone know where i can find information regarding java accessing manipulating HTML DOM please
    Thanks in advance for the help people.

    Cool Thanks for your replies. At least i know that it cant be done i wont look for anything on HTML DOM .....
    I dont believe i didnt see that method of implementation for the vector problem it seems so straight forward .. thats what I get for being a newb at both JSP and Javascript :)
    Thanks again gus much appreciated

  • Jsp variables to javascript array, for loop dont work.

    This works fine. con.getmake passes a different variable each time to the javascript array using a manual index.
    <script>
    make[0] = "<%= con.getmake() %>" ;
    document.write(make[0]);
    make[1] = "<%= con.getmake() %>" ;
    document.write(make[1]);
    make[2] = "<%= con.getmake() %>" ;
    document.write(make[2]);
    make[3] = "<%= con.getmake() %>" ;
    document.write(make[3]);
    </script>
    If I try and do the same with a for loop, It seems as though all the elements hold the same first variable retrieved from con.getmake, I am not getting the next variable from my java class.
    <script>
    for (var i= 0; i <= 2; i++)
    make[i] = "<%= con.getmake() %>" ;
    document.write(make);
    </script>

    Hi,
    Java is parsed once on the server which creates a HTML page, then it is passed to the client's browser where the javascript is executed. So con.getmake() is only executed once in java. You've got to execute your loop in java not javascript :
    <script>
    <%
    for (int i= 0; i <= 2; i++)
    %>
    document.write("<%= con.getmake() %>");
    <%
    %>
    </script>

  • Convert javascript array to java array

    Is there any way possible to convert javascript array to java array?

    if you will try to experiment a javascript array
    putting it to a hidden element, it will be converted
    to a string (comma delimited). You can get the value
    of that element as a string and use StringTokenizer
    class to put the values into a java arrayThanks, got it.

  • Stalling a form from loading until the initial javascript arrays are loaded

    I am looking for a way to get a form to be hidden based on the onload event. I would like to call a javascript function to initially populate some select boxes based on javascript arrays, but I would like this to happen before the page loads or at least stall displaying the select boxes until they are populated.
    The way it is setup now, when the page loads, the select boxes try to load first and then the rest of the form loads. I would like to know if there is a way to load the select boxes from the javascript arrays, then have the select boxes and other form elements show up at the same time. I have tried putting a <div> around the entire form and within the javascript populate function I first use "document.formname.div_id.style.visibility=hidden" then at the end of the select box population within the function, I use "document.formname.div_id.style.visiblity=visible". I tried this and the select boxes appear blank; it is as if the populate function doesn't work at all.
    I realize this is a very long question, but I will award you Duke Dollars if you help me out!!!

    right now, I have it set up where I click on a link which is a jsp page which forwards me to the jsp page that has all the html in it. That page is where I initially try to populate the select boxes with the javscript arrays...I also have a number of javascript functions which change the contents of the select boxes based on another select box in the form. Will i have access to those "java" arrays, [instead of using the javascript arrays], that you are suggesting in the javascript code? I do need to use whatever arrays I create in javascript functions.

  • Pass javascript array to java

    hii
    I have to pass a javascript array to my java MyAction.do . So how can i do it???
    Thnking You

    Being a Java newbie, I can't give you a definitive on how to pass the array to a client-side applet, although it should be possible.
    As for passing it to something server-side there are only a couple ways: in a GET request on the query string or in a POST. No matter what, you will have to flatten the array with some method or other, to convert it into a text string that can be parsed on the other end.
    I personally favor using hidden form elements and posting the data, because otherwise you have to worry about urlencoding your query string. You could just use javascript itself to write a series of hidden text inputs and then submit the form, so all your form handler has to do is pick up the variables.
    Let's say the array is named "myarray":
    Code:
    +<script language="Javascript">+
    document.writeln("<form name=\"myform\" method=\"POST\" action=\"myserver/myhandler.jsp\">")
    for(i = 0; i < myarray.length; i+){+
    document.writeln("<input type=\"hidden\" name=\"myarray[" i + "]\" value=\"" + myarray[i] + "\">")+
    +}+
    +document.writeln("</form>")+
    +document.myform.submit()+
    +</script>+
    I know this is clunky and "low-tech" but it will work, and has the benefit of working for any server-side platform that can handle forms

  • Unpack javascript array to cfarray

    Hi everybody,
    From a captivate quiz movie I want besides the Core Data,
    also the interaction data.
    From each action in a quiz I read out the InteractionID,
    ObjectiveID and Result and store them in 3 javascript arrays.
    One array at the moment takes 36 values. The arrays are sent
    as hidden files to a form and in the next step are stored in a
    database at the Cfserver. However, the javascript array is not
    unpacked. This means that all values form the array are stored as a
    single record value. 1 field takes 36 values. Whereas I want the
    values to be stored as 36 different record values.
    So, my question is: how do I unpack a javascript array to a
    coldfusion array and store all values as different record values to
    a database.

    When a Javascript array gets passed as a form value, it gets
    compressed into a 1-dimensional text string. This is the nature of
    web forms. As you've seen, when the data arrives at it's final
    destination, you then need to split the string back into an array.
    I don't actually know ColdFusion, but a quick web search
    indicates that you want the ListToArray() function. This is
    documented at the following link:
    ColdFusion
    Live Docs: ListToArray
    If I remember correctly, Javascript joins array elements
    using a comma, so you shouldn't need to specify a string delimiter.
    If that's not correct, take a look at your passed string to
    determine which character separates the individual result values
    and supply that as a second parameter to the function.
    Hope this helps!

  • Javascript array / jsp Bean Collection

    How can you fill a javascript array with the values of the collection?
    <jsp:useBean id="programs" scope="request" class="java.util.Collection"/>
      How can I create this array?
    <script language="JavaScript" type="text/javascript">
    var programData =
    new Array ( new Array "${programs[1].programId}","${programs[1].programName}", "${programs[1].department}"),  
                 new Array "${programs[2].programId}","${programs[2].programName}", "${programs[2].department}"),
    </script>

    I answered myself. If anyone else would like to know how to fill a javascript array with the values of a jsp beans collection.
    function collectionToArray()
    Array[rows] = [4];  
    var cnt = 0;
    <c:forEach var="sp" items="${programs}">
      rows[cnt][0] = ${sp.programId};
      rows[cnt][1] = ${sp.programName};
      rows[cnt][2] = ${sp.department};
      rows[cnt][3] = ${sp.urlLink1};
      rows[cnt][4] = ${sp.urlLink2};
      cnt++;
    </c:forEach>  
    }

  • How to get real value from selectOneChoice with javascript?

    Hi,
    How to get real value from selectOneChoice with javascript? The event.getNewValue() only gets me the index of the selected item, not the value/title.
    JSF page:
    <af:resource type="javascript">
    function parseAddress(event)
    alert("new value: " + event.getNewValue());
    </af:resource>
    <af:selectOneChoice label="Location:" value="" id="soc4">
    <af:clientListener type="valueChange" method="parseAddress" />
    <f:selectItems value="#{Person.locations}" id="si7"/>
    </af:selectOneChoice>
    HTML :
    <option title="225 Broadway, New York, NY-10007" selected="" value="0">225 Broadway (Central Office)</option>
    <option title="90 Mark St., New York, NY-10007" value="1">90 Mark St. (Central Office)</option>
    Thanks a lot.

    Something I was missing ,
    You need to add valuePassThru="true" in your <af:selectOneChoice component. I have personally tested it and got the actual value in alert box. I hope this time you got the real solution. You can also test the following code by your end.
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
    <af:document id="d1">
    <af:form id="f1">
    <af:panelBox text="PanelBox1" id="pb1">
    <af:selectOneChoice label="Set Log Level" id="soc1"
    value="#{SelectManagedBean.loggerDefault}"
    valuePassThru="true">
    <af:selectItem label="select one" value="First" id="s6"/>
    <af:selectItem label="select two" value="Second" id="s56"/>
    <af:clientListener method="setLogLevel" type="valueChange"/>
    </af:selectOneChoice>
    <af:resource type="javascript">
    function setLogLevel(evt) {
    var selectOneChoice = evt.getSource();
    var logLevel = selectOneChoice.getSubmittedValue();
    // var logLevelObject = AdfLogger.NONE;
    alert("new value is : " + logLevel);
    //alert(evt.getSelection);
    //alert(logLevelObject);
    evt.cancel();
    </af:resource>
    </af:panelBox>
    </af:form>
    </af:document>
    </f:view>
    </jsp:root>

  • After adding a flashfile .swf into a dreamweaver page and trying to run it, I get an error message related to Javascript

    after adding a flashfile .swf into a dreamweaver page and trying to run it, I get an error message related to Javascript
    I have no trouble viewing other websites with (most likely), flashfiles.
    Here is the the PopUp message:
    "Adobe-warning Adobe Flash PLayer has stopped a potentrially unsafe operation......"

    In newer versions of Flash Pro, you can export to HTML5 Canvas, that's probably what they're talking about: Flash Professional Help | Creating and publishing an HTML5 Canvas document
    .FLV and .SWF are Flash formats that won't show up on iOS (or an ever increasing number of other mobile devices). Mobile Flash was killed by Adobe a couple years ago, so the number of mobile devices that can see it is dwindling rapidly, don't use those formats if you want your viewers on mobile devices to see your content.

  • How to get input from keyboard scanner into an array

    This is probably a very basic question but I'm very new to java..
    My task is to reverse a string of five digits which have been entered using keyboard scanner.
    E.g. - Entered number - 45896
    Output - 69854
    I used the StringBuffer(inputString).reverse() command for this, but i need a more basic method to do this.
    I thought of defining an array of 5
    int[] array = new int [5];
    and then using,
    Scanner scan = new Scanner(System.in);
    to enter the numbers. But I can't figure out how to get the five input numbers into the array.
    If I can do this I can print the array in reverse order to get my result.
    Any other simple method is also welcome.

    Hey thanks for the quick reply,
    But how can I assign the whole five digit number into the array at once without asking to enter numbers separately?
    E.g. - if entered number is 65789
    Assign digits into positions,
    anArray [0] = 6;
    anArray [1] = 5;
    anArray [2] = 7;
    anArray [3] = 8;
    anArray [4] = 9;
    I'm really sorry but I am very new to the whole subject.

  • Adobe Acrobat 9: Javascript array populated combo box - Selected answer will not save

    I have a combo box on one of my forms that is populated using a Javascript array.  The combo box is populating just fine, but when an item is selected from that combo box, the selected item does not save when the user saves the document.  Any suggestions as to what the problem is and how it can be corrected?  I am a loss as to where to even begin looking.  Any help is greatly appreciated.
    Thank you.
    Lisa

    You might also want to check the Scripting forum
    http://forums.adobe.com/community/acrobat/acrobat_scripting

  • Populating a javascript array with datatable data

    I want to populate a javascript array with datatable data.
    How do I do this?
    I want the javascript array to be populated as the datatable is displayed.
    Doing this way doesn't work.
    <h:dataTable value="#{pmManager.profiles}" var="pmProfile" binding="#{pmManagerUiBean.uiTable}" ">
    <script>
    allProfilenames[index]='#{pmProfile.profileName}';
              alert("index ="+index);
              alert("...1"+allProfilenames[0]);
              alert("...2"+allProfileRes[0]);
              index++;
    </script>
    <h:dataTable>

    In Javascript do something like this:
    document.getElementById('form1:dec_param');
    where form1:dec_param is the id of the component on the page source (html)

Maybe you are looking for