0

If I have a JavaScript array, say angleChanges = [a,b,c]

I want to store each of these values according to a user id (let's say it is an int). I am using SQL Server Management Studio and using ColdFusion to transfer variables to the server's SQL table. How do I loop through a JS array and transfer those values to the server? The user ID will be known ahead of time, but the array represent variables that will be unknown when the page loads. They will be created within the script. The values need to be stored in this way:

User ID:1 Array_Index:1 Array_Value:a

User ID:1 Array_index:2 Array_Value:b

User ID:1 Array_index:3 Array_Value:c

User ID:2 Array_index:1 Array_Value:a

User ID:2 Array_index:2 Array_Value:b

etc

        for (var i = 1; i <= angleChanges.length; i++) {
            /*index = document.createElement("index");
            index.innerHTML = i;
            document.body.append(index);*/
            <cfquery datasource="exmind">
            update dbo.sf_angles
            set angle_change_number = i, angle_change = angleChanges[i-1]
            where subject_id = #subject_id#
            </cfquery>
        }

This is what I want to do, but I do not know how to use i in cfquery, or the values in angleChanges (these would be the a,b,c values)

  • What have you attempted to achieve this? Where are you running into trouble? Do you have your database table set up already? – mykaf Aug 23 '22 at 16:42
  • My table is already set up, I just want to insert these values. I know how to use cfquery, I just need to know how I can use a JS variable within cfquery, or create a new variable that can be used there without leaving the page – Bayley Sapara Aug 23 '22 at 17:01
  • 5
    You'll have to send it either via a form or ajax. Your javascript is executed on the client side, while the `` is on the server side. – mykaf Aug 23 '22 at 18:00
  • Can you direct me to some source code that would show me how to do this? I am not sure how to start - have never worked with forms or ajax – Bayley Sapara Aug 23 '22 at 18:17
  • Why not start with the [ColdFusion documentation](https://helpx.adobe.com/coldfusion/developing-applications/requesting-and-presenting-information/introduction-to-retrieving-and-formatting-data/working-with-action-pages.html)? – mykaf Aug 23 '22 at 18:37
  • 1
    Take a look at https://stackoverflow.com/questions/70218578/coldfusion-lucee-multiple-conditional-select-via-ajax/70294949#70294949 it might help you understand the interactions of html, javascript and cfml. – AndreasRu Aug 23 '22 at 21:12
  • 2
    Please provide enough code so others can better understand or reproduce the problem. – Community Aug 24 '22 at 08:22
  • 3
    Also perhaps read this: https://blog.adamcameron.me/2012/10/the-coldfusion-requestresponse-process.html. You have a fundamental lack of understanding how HTTP requests work, and Stack Overflow is not the mechanism for you to get up to speed with it. You need to understand your tools before you a) start using them; b) as for help. (NB: this is not meant as a slight at all... just you need to do some research/learning before jumping into this stuff). – Adam Cameron Aug 24 '22 at 08:28

0 Answers0