SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    "Unexpected end of input" error

    I'm getting this error from the following code and can't figure out where the missing closing element is. This is the only code on the page:

    Code:
    function setItemForm1b() {
        var form1b = document.getElementById('form1b'),
            SOneDateFrom = document.getElementById('SOneDateFrom'); 
        localStorage.setItem('SOneDateFrom', JSON.stringify(SOneDateFrom.value));
    }           
    /* 
    "Unexpected end of input" usually means a closing element is missing. 
    */
    function getItemForm1b() { 
        var SOneDateFrom = localStorage.getItem('SOneDateFrom'); 
        form1b.SOneDateFrom.value = JSON.parse(SOneDateFrom);
    }
        
    function deleteStorage() {
        form1b.SOneDateFrom.value = localStorage.setItem('SOneDateFrom',''); 
        if (form1b.SOneDateFrom.value === "undefined") {
            form1b.SOneDateFrom.value = ""; 
        }
    }
    Does "Unexpected end of input" indicate a different kind of problem at times?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The JSON parser returns that error when it cannot make a properly formatted JSON string from the input, and when it fails to create an object with JSON.parse.

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Strange ... all I entered was 123

    Thanks. What should I do differently?

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try including quotes, but if your values are strings, why are you using JSON at all?

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I probably misunderstood the instructions when I was creating the pages!

    I notice that without JSON, quotes are inserted around the string when read back into the field. Yuck.

    My test page, with all code on one page, worked fine. Now on separate pages, it refuses to work.


Bookmarks

Posting Permissions

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