Passing parameters from JSP to JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Omar

    Passing parameters from JSP to JavaScript

    Hi!

    I have a JavaScript function that receives an Array with words. This
    Array can be gotten from a query to a DB using JSP.

    The JavaScript function is executed when onFocus event occurs:
    <input type='text' onFocus='myFunc tion(this.event , myArray);' />

    myArray is declared as:
    <script>
    var myArray = new Array('j'habite ', 'tu habites', 'il habite');
    </script>

    I want to tell JavaScript:
    var myArray = myJSPArray;
    Where myJSPArray is declared some where in the JSP document.

    Is it possible? If so, how can I do it?
    TIA!
  • Tom Dyess

    #2
    Re: Passing parameters from JSP to JavaScript

    "Omar" <ro_omar@yahoo. com> wrote in message
    news:8b974ca4.0 503101544.33d4f aca@posting.goo gle.com...[color=blue]
    > Hi!
    >
    > I have a JavaScript function that receives an Array with words. This
    > Array can be gotten from a query to a DB using JSP.
    >
    > The JavaScript function is executed when onFocus event occurs:
    > <input type='text' onFocus='myFunc tion(this.event , myArray);' />
    >
    > myArray is declared as:
    > <script>
    > var myArray = new Array('j'habite ', 'tu habites', 'il habite');
    > </script>
    >
    > I want to tell JavaScript:
    > var myArray = myJSPArray;
    > Where myJSPArray is declared some where in the JSP document.
    >
    > Is it possible? If so, how can I do it?
    > TIA![/color]

    No, you'll need to create the array dynamically in the jsp code in js for
    the other js to access it.

    --
    Tom Dyess
    OraclePower.com


    Comment

    • RobB

      #3
      Re: Passing parameters from JSP to JavaScript

      Omar wrote:[color=blue]
      > Hi!
      >
      > I have a JavaScript function that receives an Array with words. This
      > Array can be gotten from a query to a DB using JSP.
      >
      > The JavaScript function is executed when onFocus event occurs:
      > <input type='text' onFocus='myFunc tion(this.event , myArray);' />
      >
      > myArray is declared as:
      > <script>
      > var myArray = new Array('j'habite ', 'tu habites', 'il habite');
      > </script>
      >
      > I want to tell JavaScript:
      > var myArray = myJSPArray;
      > Where myJSPArray is declared some where in the JSP document.
      >
      > Is it possible? If so, how can I do it?
      > TIA![/color]

      You can tell JavaScript anything you want - but in the end, it has no
      knowledge of what goes on at the server, it just processes whatever you
      load into the (local) programming environment. This:

      var myArray = myJSPArray;

      ....'tells' JS to set a reference at variable myArray pointing to
      something at variable myJSPArray...if there's a JS array there, fine,
      although the utility of the reference is unclear. As mentioned, there's
      no point in downloading jsp code to the JavaScript engine, which
      doesn't speak it.

      This looks wrong:

      onFocus='myFunc tion(this.event , myArray);

      You pass a handable Event object inside an HTML event handler with the
      local variable *event*. 'this' refers to the Input object in this
      context.

      If 'myArray' is global - not necessarily the best thing - you don't
      need to pass it anyway, as it'll be visible to the function as well.

      Comment

      Working...