www.webdeveloper.com
Results 1 to 2 of 2

Thread: Javascript LocalStorage Setting Other Variables To $0.00

  1. #1
    Join Date
    Jun 2011
    Posts
    13

    Javascript LocalStorage Setting Other Variables To $0.00

    If I assign a value to one variable then it sets the other variable to $0.00. So if I set the matinee price to $3.00 then the Before Noon price becomes $0.00.(See attached image for example) If I set a new value to both variables then there aren't any issues, but I want to be able to set a new value to one variable and not have the other values change if I don't update them as well.

    Code:
    // JavaScript Document
    var beforenoonprice = 6.75; // CHANGE THE PRICE OF THE BEFORE NOON TICKET
    var matineeprice = 9.00; // CHANGE THE PRICE OF THE MATINEE TICKET
    var seniorprice = 9.25; // CHANGE THE PRICE OF THE SENIOR TICKET
    var militaryprice = 9.25; // CHANGE THE PRICE OF THE MILITARY TICKET
    var studentdayprice = 8.00; // CHANGE THE PRICE OF THE STUDENT DAY TICKET
    var seniordayprice = 6.75; // CHANGE THE PRICE OF THE SENIOR DAY TICKET
    var adultprice = 10.75; // CHANGE THE PRICE OF THE ADULT TICKET
    var childprice = 8.00; // CHANGE THE PRICE OF THE CHILD TICKET
    var threeDprice = 3.50; // CHANGE THE PRICE OF THE REGULAR 3D PRICE
    var imaxPrice = 4.50; // CHANGE THE PRICE OF THE IMAX TICKET
    var imax3dPrice = 5.50; // CHANGE THE PRICE OF THE IMAX 3D TICKET
    var output = document.getElementById('output');
    
    
    function updatePricingFunction() {
        var beforeNoonFieldChange = document.getElementById('beforeNoonNPSlot').value;
        var matineeFieldChange = document.getElementById('matineeNPSlot').value;
    
        localStorage.setItem('text', beforeNoonFieldChange);
        localStorage.setItem('text1', matineeFieldChange);
    
    
    }
    
    function load() {
    
        beforenoonprice = storedValue;
        matineeprice = storedValue1;
        var storedValue = 1; // default value;
        if (localStorage['text'] !== undefined) { // does the local store exist.
    
            if (!isNaN(localStorage['text'])) { // is it a number
    
                storedValue = Number(localStorage['text']); // all good covert it from String to Number
    
            }
    
        }
        var storedValue1 = 1; // default value;
        if (localStorage['text1'] !== undefined) { // does the local store exist.
    
            if (!isNaN(localStorage['text1'])) { // is it a number
    
                storedValue1 = Number(localStorage['text1']); // all good covert it from String to Number
    
            }
    
        }
    
    
    
        beforeNoonCPSlot.innerHTML = "$" + parseFloat(storedValue).toFixed(2);
        $("#beforeNoonPrice").attr = parseFloat(storedValue).toFixed(2);
    
        $('#beforeNoonPrice').append("$" + (storedValue * 1).toFixed(2));
    
        matineeCPSlot.innerHTML = "$" + parseFloat(storedValue1).toFixed(2);
        $("#matineePrice").attr = parseFloat(storedValue1).toFixed(2);
    
        $('#matineePrice').append("$" + (storedValue1 * 1).toFixed(2));
    
    }
    Attached Images Attached Images
    Last edited by andynov123; 08-05-2014 at 08:32 PM.

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,506
    I would suggest for simplicity that you access the various input fields via JavaScript and not JQuery or whatever framework you are using.

    It also helps if you have HTML to accompany the script.

    Is this school work by any chance?
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles