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
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Assigning javascript variable to JSP variable using form submit or building a query

    Hi Geniuses,

    I am developing a jsp page in which it takes input using javascript prompt
    and i want to assign this value to Jsp variable I am not able to do it, Pls help me in this regard.

    I have come across this problem in various forums and the standard answer given is use form submit or build a query. But no code along with it.

    Since, this forum is different and people out here are very helpful I request you to send in the code snippet for assigning a value of javascript variable to a jsp variable by using submit form and if possible by building a query as well.

    Thanks a billion,
    Kubra.

  • #2
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am still waiting......

    Have i posted this in the right forum?

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    They are correct when they said you need to use form submission. You must be mistaking it that the server-side and client-side codes are executed as it is encountered in the page. That is, when a javascript prompt is invoked and the user types something, the returned value can be directly set to a jsp variable below it and then the server-side processing continues.

    <script type="text/javascript">
    var ans = prompt("...","");
    </script>
    <%
    String s = ans;
    %>

    That will definitely not work. Take note that all server-side codes are processed first on the server then the server sends the generated html and javascript codes to the browser. The browser then renders the html and runs the javascript codes on the client-side.

    So to do what you want, you need to store the return of the prompt dialog to a hidden field and then submit the form.
    Or you can append the entered data in the URL querystring while redirecting to a jsp page.

    var ans = prompt("Enter something:","");
    location.href="process.jsp?ans=" + escape(a);

    and then in process.jsp, retrieve the url parameter and do the necessary action on it.
    The actual implementation depends on what you really want to accomplish.

  • #4
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you Glenn...You really are a helpful member.

    Similarly can you send me the code when form submission method is used...code snippets in jsp page..

    Thanks once again,
    Kubra.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Please describe first in detail what you want to do.


  •  

    Posting Permissions

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