Skip to main content
Inspiring
September 30, 2010
Question

Add dinamic value to javascript.

  • September 30, 2010
  • 1 reply
  • 430 views

I know that the solution is probably simple, however I can not hanle it since javascript is not really my thing. Now, I just want to add a dynamic value to javascript, for example ID and pass it (on button click) with the same script to previously built Coldfusion page.

here is an example

<cfquery name="test11" datasource="datasource">
SELECT *
FROM database
</cfquery>

<cfset javaDinamicID= #test11.ID# >

and javascript, something like this

<script language="javascript" type="text/javascript">
function testDinamicID() {
req=new XMLHttpRequest(); req.open('GET','/JavaID.cfm?ID='     this part here I cannot handle, how to add a dynamic value here     +1+'&'+'NAME='+aaa,false); req.send(null);
}
</script>

Am I on the right track?

    This topic has been closed for replies.

    1 reply

    ilssac
    Inspiring
    September 30, 2010

    pirula08 wrote:

    Am I on the right track?

    Yup.

    You do it just like you would do it to output HTML in a table or something.

    <cfoutput query="test11"

         <script language="javascript" type="text/javascript">
            function testDinamicID() {

              req=new XMLHttpRequest(); req.open('GET','/JavaID.cfm?ID=#test11.someID#&'+'NAME='+aaa,false); req.send(null);

            }
         </script>

    </cfoutput>

    pirula08Author
    Inspiring
    October 3, 2010

    Your answer is 99% accurate.

    I just want to create like/dislike buttons like those on youtube, so this was the easy part. Anyway now when i know a little bit more about javascript I'll do my best to handle everything else.

    Thanks ilssac