Passing values from javascript to JSP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RAKESH BALAIAH
    New Member
    • Dec 2010
    • 6

    Passing values from javascript to JSP

    I am working on a project in which i need to receive values from the user and display it dynamically below the form. After the user confirms to save it i need to save all those values in database..

    I am using Javascript to display the values as they enter.But i dont know how to send those array of values to the JSP page so that i can store them in the database.

    I'm stuck.. Kindly help me out.. :(

    This is similar to a shopping cart where the user data needs to be displayed dynamically in the same page as and when the user selects. I've been asked to use JavaScript for the cart and after receiving final confirmation from the user the data needs to be stored in the database using JSP..

    Kindly help me out.. Am really really stuck.. :(
    Last edited by RAKESH BALAIAH; Jan 1 '11, 06:51 AM. Reason: Detailed info regarding the problem
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Either you have to use Ajax or Form submission to pass the values. Use some hidden input fields and assign the values in the text box.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • RAKESH BALAIAH
      New Member
      • Dec 2010
      • 6

      #3
      Thanks Ramanan..
      I really like your advice..
      But i've constraint that i should complete this project using JSP and javascript alone..
      So if u can give me a better solution i would be much glad..

      Thanks and regards,
      RAKHI

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        I guess setting a hidden variable with the JS in a Form doesn't uses any language.

        Ex:

        HTML:

        Code:
        <input type="hidden" name="usrName" id="usrName" />
        JS:

        Code:
        var frmElement = document.getElementById('usrName');
        frmElement.value=yourArray;
        JSP:

        Code:
        String str = request.getParameter('usrName').toString();
        Thanks and Regards
        Ramanan Kalirajan

        Comment

        • Jerry Joy
          New Member
          • Oct 2011
          • 1

          #5
          Hi Rakesh,

          Did this suggestion help you?

          Comment

          Working...