Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Using JSP to extract values from a JS file

Background Info
================
I am using Javascript as a shopping cart for a college project.  The script allows users to add items to the shopping cart, and it holds the values in the .JS file, until the user checks out.

Problem Definition
==================
My knowledge of Javascript is horrible, but I am fairly sufficient with JSP.  I want to be able to grab the values submitted in the forms to the JS, and call these values in a JSP so that I can update my database accordingly.

The sequence of events would look like this:

1)User is in catalogue
2)User submits purchases via form
3)HTML file calls .JS file to grab values for further use
4)User confirms order in a JSP page, user inputs id and password to submit order
5)Another JSP will call values from .JS file in order to execute a database Update for the order

I hope this was clear.  Thank you very much for your help.

-- Jeef
0
jeef
Asked:
jeef
  • 2
  • 2
  • 2
1 Solution
 
damonfCommented:
When you are performing client-side javascript operations, the data are not "held in a .JS file" as you say.  Rather, they are held in the browser's memory.  Unless the user submits a form, your server doesn't know about the values.

0
 
kennethxuCommented:
damonf was correct, you need to redefine your logic.
0
 
jeefAuthor Commented:
Perhaps I am still mistaken, but...the values are submitted in the form, and then taken by the .JS.  If that is possible.  

If you are correct, however, how would the browser hold the information? Would it be in a cookie file?

Thanks again

--Jeef
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
damonfCommented:
The ".JS file" is simply the source code for the javascript programs.  It gets interpreted by and run by the browser.  That is its only function.

When code runs on the browser, information is held in a variety of ways.  Just think of your browser as another code platform.  It has memory and storage, although the "storage" is pretty limited because of the sandbox architecture for the browser...you aren't generally allowed to touch the end user's disk drive.  You can store variables in memory, but they will only persist until the next form submission (unless your code is running from a frame that doesn't reload).  Storing data in cookies is one option, but this is not recommended for large amounts of data.  Another option is to write out your data to form fields that get submitted.

I think what you want to do is submit values to the server and hold them in session variables until the user checks out.  
0
 
kennethxuCommented:
.js file contains javascript code. javascript is client side language and jsp is server side language.

when you say submit form, it means browser submit form data to server. at the server side, only jsp/servlet can process the form, not the javascript. but you can process data before you submit the form to server by javascript only in browser side.
0
 
jeefAuthor Commented:
I did some thinking based on what you guys said, and I think I now have a good idea at what I need to do.

Thanks a million.

--Jeef
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now