How pass varible to the JavaScript Function

Discussion in 'JavaScript' started by nikoo56, Jul 15, 2010.

  1. #1
    I have a coldfsuion varible that is need to sent to the javascript function , I am not sure how to do this:
    <cfset Id = getRpcmtHistory.LeadId> /Id is the variable that has numeric value
    <a href="javascript : poponload();">

    /what should I put in () when I put Id it gave me an error that Id is not identify.

    Also what should I put in JavaScript function at the top:
    function poponload(?)
    {
    }
     
    nikoo56, Jul 15, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    I'm not too familiar with ColdFusion but this is how we usually pass a variable to a function in javascript:
    
    <html>
    <body>
    
    <script type="text/javascript">
    function watever (the_variable) {
       alert(the_variable);
    }
    </script>
    
    <a href="#" onclick="watever('YES');">Link</a>
    </body>
    </html>
    
    HTML:
    Also, keep in mind on what you're passing because '5' and 5 are not the same.
     
    Rainulf, Jul 15, 2010 IP
  3. nikoo56

    nikoo56 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply, in this case YES has been pass to the function as a fix string, I want to pass variable for example consider Var Id;
    Id sometime is 1, or 2, or 3, and so on so I need to send variable Id not the actual 1,2, 3.
     
    nikoo56, Jul 15, 2010 IP
  4. NedBool

    NedBool Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <cfset Id = getRpcmtHistory.LeadId[i]>
    
    <script type="text/javascript"  language="JavaScript">
        <cfoutput>
            var #toScript(Id, "ident")#;
        </cfoutput>
    </script>
    Code (markup):
    This should create a JavaScript variable called ident holding the value of Id ( ColdFusion ).

    ** I'm not by any means a ColdFusion expert but it *should* work as expected.
     
    NedBool, Jul 15, 2010 IP