Cfquery to javascript array to .js file

Hi guys,
I've got a small problem out there:
have cities table in the database therefore pulling out everything using cfquery .
<cfquery name="get_city" datasource="IGES">
SELECT *
FROM cities
ORDER BY City ASC
</cfquery>
Now all these city names from database needs to be passed to .js file in some sort of array
<script type="text/javascript" src="../jscripts/add_school.js"></script>
^^^^^^^^that's the file all the javascript is in
Is there any way to pass an array made from cfquery to javascript file where it can be used to populate listbox.
cheers,
Simon

Hi Ian,
Thanks a lot, that toScript() stuff did the job properly.
cheers,
Simon
"learning every day"

Similar Messages

  • CFquery to javaScript Array to Listbox

    Help!
    Here's what I've got so far:
    <html xmlns="
    http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <cfquery datasource="ERMRiskMgmt" name="DelegateList">
    SELECT CoordFirst + ' ' + CoordLast AS 'AvailDelegate',
    CoordID
    FROM dbo.ERMCoordinators
    ORDER BY CoordLast
    </cfquery>
    <script language="javascript" >
    function addOption(selectbox,text,value )
    var optn = document.createElement("option");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
    function addOption_list(selectbox)
    var nator = new Array(<cfoutput
    query="DelegateList">"#AvailDelegate#",</cfoutput>"");
    for (var i=0; i < nator.length;++i)
    addOption(document.drop_list.DelegateSelect, nator
    , <cfoutput
    query="DelegateList">#CoordID#</cfoutput>);
    </script>
    <title>Untitled Document</title>
    </head>
    <body onload="addOption_list()";>
    <form name="drop_list" action="" method="post" >
    <select name="DelegateSelect">
    <option value="" ></option>
    </select>
    </form>
    </body>
    </html>
    I realize those 2 queries arent 'associated' yet - still
    workin on that - Help! Ty!

    End Result, Display a Listbox with the Coordinator Fullnames,
    having the value
    of that Coordinators ID.
    I'm using the Array Because the 'form' is inside a CFOUTPUT
    for a list of
    reports, not directly related to this CFOUTPUT of coordinator
    Names. Its there
    to allow for the delegation of reports to members of the
    'Coordinator Table' .
    I hope that claifies...?

  • Ouput javascript array to .txt file

    My javascript program includes a 2D array and stores some information into this 50 * 20 array. I need to output this information into a .txt or any other format file.
    Does anyone know how to do that in javascript.

    And you want the JSP to do the outputting as it generates the javascript, or you want the javascript to do the outputting when it executes in the browser?
    I'm guessing it's the latter, as outputting something on the server would be a poor idea, and that would make it a question about javascript. Which I don't know the answer to. My guess is that javascript doesn't have the ability to write to files on the client because that would be a serious security hole, serious enough to make almost everybody disable javascript.

  • Javascript to upload a file to SharePoint 2010 document library

    Please share your ideas. I am using SharePoint 2010. Currently when uploading files to a document library, first the upload form is opening to upload the document and then the edit form. I would like to have both this in the same form. I am trying to
    create a webpart page with the controls to upload the file to document library and assign values to the fields in the library. I am looking for some javascript for doing this. Is there any other way of achieving this? Please share any sample
    code.
    <label for="title">Enter the title for this document:</label> <input type="text" id="title"><br/><br/>
    <input id="inputFile" type="file"/><br/><br/>
    <input id="uploadDocumentButton" onclick="UploadDocument()" type="button" value="Upload Document"/><script type="text/javascript">
            function UploadDocument() {
                //javascript to upload the file to MyLibrary and update the title field
    </script>

    Use the below code step by step :) 
    (1) Html
      <input type="file" id="attafh"  class="AlltextAccount"  />
          <input type="button" value="upload" onclick="rundCode()" />
    (2) JS File 
    function rundCode() {
        var file = document.getElementById('attafh').files[0];
        if (file) {
            UploadMe(file);
    (3) 
    function UploadMe(readFile) {
        var reader = new FileReader();
        reader.readAsArrayBuffer(readFile); //array buffer
        reader.onprogress = updateProgress;
        reader.onload = loaded;
        reader.onerror = errorHandler;
    (4)
    function loaded(evt) {
        var fileString = evt.target.result;
        var X = _arrayBufferToBase64(fileString); // this is the mothod to convert Buffer array to Binary
            var fileInput = document.getElementById('attafh');
            var fileDisplayArea = document.getElementById('fileDisplayArea');
                var file = fileInput.values;
                 var filePath = $('#attafh').val(); // "c:\\test.pdf";
            var file = filePath.match(/\\([^\\]+)$/)[1];
            var soapEnv =
                "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
                    <soap:Body>\
                        <CopyIntoItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
                            <SourceUrl>" + filePath + "</SourceUrl>\
                                <DestinationUrls>\
                                    <string>http://intranet/sites/English/DocumentLibrary/" + file + "</string>\
                                </DestinationUrls>\
                                <Fields>\
                                    <FieldInformation Type='Text' DisplayName='Title' InternalName='Title' Value='Test'  />\
                                      <FieldInformation Type='Text' DisplayName='BudgetId' InternalName='BudgetId' Value='8'  />\
                                </Fields>\
                            <Stream>" + X + "</Stream>\
                        </CopyIntoItems>\
                    </soap:Body>\
                </soap:Envelope>";
            $.ajax({
                url: "http://intranet/_vti_bin/copy.asmx",
                beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"); },
                type: "POST",
                dataType: "xml",
                data: soapEnv,
                complete: processResult,
                contentType: "text/xml; charset=\"utf-8\""
        SP.SOD.executeOrDelayUntilScriptLoaded(initialize, 'SP.js');
        SP.SOD.executeOrDelayUntilScriptLoaded(test, 'SP.js');
    function errorHandler(evt) {
        if (evt.target.error.name == "NotReadableError") {
            // The file could not be read.
    function _arrayBufferToBase64(buffer) {
        var binary = ''
        var bytes = new Uint8Array(buffer)
        var len = bytes.byteLength;
        for (var i = 0; i < len; i++) {
            binary += String.fromCharCode(bytes[i])
        return window.btoa(binary);
    (5)
    function updateProgress(evt) {
    http://www.abdulazizfarooqi.wordpress.com Abdul Aziz Farooqi [BizTalk & SharePoint Consultant] MCPD Web & MCPD SharePoint 2010

  • 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.

  • 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!

  • How to retrieve arrays from a file.

    If i were to save 5 arrays to a file like this.....
    DataOutputStream output;
         DataInputStream input;
         Date today = new Date();
         String filename = "phonebook";
    private String name[] = {""};
         private String surname[] = {""};
         private String home[] = {""};
         private String work[] = {""};
         private String cell[] = {""};
         try
                   output = new DataOutputStream(new FileOutputStream(filename));
              catch(IOException io)
                   JOptionPane.showMessageDialog(null,"This program could not create a storage location. Please check the disk drive and the tun the program again.","Error",JOptionPane.ERROR_MESSAGE);
                   System.exit(1);
    public void save()
              try
                   for(int i=0; i < name.length; i++)
                        output.writeUTF(name);
                        output.writeUTF(surname[i]);
                        output.writeUTF(work[i]);
                        output.writeUTF(home[i]);
                        output.writeUTF(cell[i]);
                   JOptionPane.showMessageDialog(null,"Data succesfully saved to file.","Information message",JOptionPane.INFORMATION_MESSAGE);
              catch(IOException io)
                   System.exit(1);
         }And then I want to use them again on my startup. How would I go about initialising them back into thier origianl arrays. What i mean is I want the arrays to contain theier previous saved values. Is this possible.
    I tried to do it like this but it wont work. I get no errors. It just wont return and strings at all.try
                   input = new DataInputStream(new FileInputStream(filename));
              catch(IOException io)
                   JOptionPane.showMessageDialog(null,"Could not find the correct file to read data from.","Error",JOptionPane.ERROR_MESSAGE);
              try
                   for(int i=0; i< name.length; i++)
                        name[i]=input.readUTF();
                        surname[i]=input.readUTF();
                        work[i]=input.readUTF();
                        home[i]=input.readUTF();
              cell[i]=input.readUTF();
              catch(IOException io)
              }Or is it better to create a seperate file for each array?
    Edited by: Yucca on Mar 23, 2008 2:24 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Any help here please.
    Edited by: Yucca on Mar 23, 2008 6:34 PM

  • 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

  • JavaScript To Save A File In Adobe 8?

    Can anyone show me a sample JavaScript to save a file in Adobe 8?
    I tried using "Execute a menu item
    File>Save"
    but it doesn't seem to work in adobe 8.

    Adobe does not consider this a 'safe' menu item and has removed from the list of menu items that can be executed. There is more information available in Acrobat JS API Reference.

  • Writing an integer array to a file...

    Okay, so I just wanna write a sorted integer array to file... but I'm having a problem or two.
    int[] array = read(new File("C:\\college work\radixsort.txt");
    radixSort(array, array.length);That text file is a list of 30 numbers.
    After the radixSort method is called the values in the text file are sorted into the correct order. Then I want to write the sorted values to a text file radixSorted.txt
    I had too many problems with printArray() so I figured this could be easier.
    I have tried FileInputStream and FileWriter but no luck.
    I don't want the answer, but just something to help point me in the right direction.
    Thank you.

    pri.println(char[] x) looks like the one I am looking for.
    I have modified the code. I've placed only the println part inside the loop now, but it's just the pri.println(char[], array) now. I'm nearrrrly there! (I think).
    try
                   PrintWriter pri = new PrintWriter(new FileWriter("C:/college work/radixsort.txt", true));
                   for (int h = 0; h < array.length; h++)
                        pri.println(char[], array);
              catch (Exception e)
                   e.printStackTrace();
                   System.out.println("No such file exists.");
              finally
                   pri.close();
              }Edited by: JayJay88 on Nov 8, 2008 1:16 PM

  • 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

  • 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)

  • Write Text Data Array to text file

    Greetings all. I hope someone can help me as I am really under the gun. The attached vi shows the basics of what I am trying to do. I have already written a vi that takes the Cal Data Array and prints it out in a nicely formatted report. My problem is that the powers that be also want the data saved to a generic text file that can be copied and printed out anywhere they like. As such, I need to save the data to a generic text file in column format such that it will all fit on one page in landscape mode. There are a total of 12 columns of data. I have been trying to create something that would format each column to a specific length instead of them all being the same. No luck so far. Basically, I need columns 1,2,3,8 and 12 to be length of 5. The rest a length of 9. I have tried to place the formatting part in a for loop with the formatting in a case, but it does not appear to work. I really need this quick so if anyone has any ideas, please help. As always, I really appreciate the assistance.
    Thanks,
    Frank
    Attachments:
    Write Cal Data to Text File.vi ‏21 KB

    pincpanter's is a good solution. Beat me to it while I was away building an example. Similiar approach using two for loops and case statement. Here is my suggestion anyway....
    cheers
    David
    Message Edited by David Crawford on 11-23-2005 09:37 AM
    Attachments:
    Write Text Data Array to text file.vi ‏31 KB

  • Saving and loading 1D array to/from file

    Hi,
    i have some problems with my NI application. for the first, i have case structure with two cases: true and false.
    FALSE: in this case i have a for loop with 100 samples. i catch signal from my DAQ (now just Simulate Signal) and what i want is to save it in a 1D array and at the end of the loop the COMPLETE array into one text file. Problem in my vi: just the values from the last iteration are saved.
    TRUE: now i have while loop. AT THE BEGINN of the loop i need to load my array from the file and not in the middle of the loop. Why? The data from the file are needed during the loop.
    thanx in advance
    Vedran Divkovic
    RUB GERMANY
    Attachments:
    Regelsystem.vi ‏1494 KB

    According to your code, what you are saving is an array of means (one from each iteration), and NOT the last iteration. If you want to keep the entire data, it would be a 2D array.
    Why are you generating an entire waveform at each iteration? Shouldn't you just generate one point?
    LabVIEW Champion . Do more with less code and in less time .

  • Javascript to Optimise a file at 150 and Retain/Embed all the fonts

    I need a Javascript to Optimise a file at 150 and retain and embed fonts.
    Any Help?
    Acrobat version 9.

    Ok, I can see the permission problem now:
    java.security.AccessControlException: access denied (java.io.FilePermission c:\myfile.txt read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
    Edited by: user10047839 on 1-feb-2013 7.29
    signing the Jar and downloading the certificate permanently does not change anything in Firefox. The Java console keeps giving the above exception.
    Any idea?

Maybe you are looking for