hello forums.
i have small problem im creating a simple page (no php ) just javascript and html.

i have order.html which has a list of items.
and then when you click the drop down menu it will automatically display the price of the item depending on the quantity on a textbox.

now i have form.htm
i have the values name,address,ammount.

now how can i pass the value of the textbox with the price to the form.htm so i can subtract them?
any help? thanks!

Recommended Answers

All 4 Replies

There are many ways of doing this.Once you submit a form with GET method then use one of these methods:-

  • Split the URL by searching for "?" and then take 2nd element of array and then split it by "&".Now you have query parameters.Now split the resultant data by "=" and decodeURIComponent.

    var queryName = decodeURIComponent(queryItem[0]);
    var queryValue = decodeURIComponent(queryItem[1]);

  • Use "location.search" to get query parameters.then store data in JSON format.

    var match,
        pl     = /\+/g,  // Regex for replacing addition symbol with a space
        search = /([^&=]+)=?([^&]*)/g,
        decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
        query  = window.location.search.substring(1);
    
    var urlParams = {};
    while (match = search.exec(query))
       urlParams[decode(match[1])] = decode(match[2]);
    

This could easily be improved upon to handle array-style query strings too. An example of this is here, but since array-style parameters aren't defined in RFC 3986 I won't pollute this answer with the source code.

Although another alternative but have you any reason why you can't parse query parameters????

moreover cookies have following disadvantages

1)Cookies can be disabled on user browsers
2)Cookies are transmitted for each HTTP request/response causing overhead on bandwidth
3)No security for sensitive data(as in some broswers they are not encrypted and stored)

Cookie Limitations:
1)Most browsers support cookies of up to 4096 bytes(4kbytes)
2)Most browsers allow only 20 cookies per site; if you try to store more, the oldest cookies are discarded.
3)Browser supports 300 cookies towards different websites.
4)Complex type of data not allowed(eg: dataset), allows only plain text (ie, cookie allows only string content)
5)Cookies are browser specific (ie, one browser type[IE] stored cookies will not be used by another browser type[firefox]).

Refer http://books.google.co.in/books?id=NLc_TQiWvo4C&pg=PA546&lpg=PA546&dq=cookie+disadvantages&source=bl&ots=TO5Su3IztL&sig=drx5wX6CW576jGRPH8CJlBM7TJ4&hl=en&sa=X&ei=tjk6Uc_UGMSOrgewm4DgDw&sqi=2&ved=0CGgQ6AEwBw#v=onepage&q=cookie%20disadvantages&f=false

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.