Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    lmc
    lmc is offline
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Assign a variable (JSP) from within a script

    I know the subject heading is not so clear but I will do my best to explain.

    Basically what I am doing is reading some values from a javascript that reads from an XML file. What I am trying to accomplish is a way to assign a variable that was declared within the "<% .. String strValue="" .... %>" section of my JSP page with a value returned from the script. Here is my code:

    Code:
    <HTML>
    <BODY>
    <%	
       String strValue = "NONE";
    %>
    ......
    
    <SCRIPT type="text/javascript">
        xmlDoc=loadXMLDoc("customers.xml");
        var x=xmlDoc.getElementsByTagName('name');
        document.write(x[2].childNodes[0].nodeValue);    
    </SCRIPT>
    
    </BODY>
    </HTML>
    As you can see in the above code the output of the script will be the 3rd node(starting from 0 to 2). I would like to assign the output of "x[2].childNodes[0].nodeValue" to the variable that was declared in the beginning "strValue".
    I have tried different combinations but since the variable needs to be encapsulated with the "<% %>" notation because of JSP, I am stumped.

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    may i ask what the purpose of this is? knowing why you need to do that would help me better understand what needs to be done, and what can possibly be done as an alternative.

    as far as i know anything within <% %> is altered on the server side, so any javascript you have in the source code will only see the output of that, and not what is actually there.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    lmc
    lmc is offline
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I am trying to do is read a value from the XML (client side) and included it as a parameter to a function being called on the server-side. I hope this helps.

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    well from what i know, server side scripts run before the client side is even made.


    the only thing i can think of that sounds anything like that would be to redirect the page to another page with the value you want to assign in the location, much like you see on this site.

    codingforums.com/newreply.php?do=

    and where it redirects to is the file that has your server side script that will strip that out and then create the var you want.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    basically, post the value to a server side script, then have the server side script create an output from it and then have it do what you wnat it to do after that i.e. create what will be displayed in the clients window.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •